For AI agents: the complete documentation index is available at /2.x/ko/llms.txt, the full documentation bundle is available at /2.x/ko/llms-full.txt, and this page is available as Markdown at /2.x/ko/guide/getting-started/quick-start.md.
v3 정식 출시. 변경 사항 보기
  • 한국어
  • 2.x
  • 빠른 시작

    예제 및 데모

    설치

    중요

    react-native-gesture-image-viewerreact-native-reanimatedreact-native-gesture-handler를 기반으로 한 높은 성능의 뷰어 라이브러리입니다.
    따라서 이 라이브러리를 사용하기 전에 React Native Reanimated와 Gesture Handler를 설치해야 합니다. 아직 설정을 하지 않았다면 설치 가이드를 참고해주세요.

    npm
    yarn
    pnpm
    bun
    deno
    npm install react-native-gesture-image-viewer@2

    기본 사용법

    react-native-gesture-image-viewer는 완전한 커스터마이징을 위해 제스처 동작에만 집중한 라이브러리입니다.

    import { useCallback, useState } from 'react';
    import { ScrollView, Image, Modal, View, Text, Button, Pressable } from 'react-native';
    import {
      GestureViewer,
      GestureTrigger,
      useGestureViewerController,
      useGestureViewerEvent,
      useGestureViewerState,
    } from 'react-native-gesture-image-viewer';
    
    function App() {
      const images = [...];
      const [visible, setVisible] = useState(false);
      const [selectedIndex, setSelectedIndex] = useState(0);
    
      const { goToIndex, goToPrevious, goToNext } = useGestureViewerController();
    
      const { currentIndex, totalCount } = useGestureViewerState();
    
      const openModal = (index: number) => {
        setSelectedIndex(index);
        setVisible(true);
      };
    
      const renderImage = useCallback((imageUrl: string) => {
        return <Image source={{ uri: imageUrl }} style={{ width: '100%', height: '100%' }} resizeMode="contain" />;
      }, []);
    
      useGestureViewerEvent('zoomChange', (data) => {
        console.log(`Zoom changed from ${data.previousScale} to ${data.scale}`);
      });
    
      return (
        <View>
          {images.map((uri, index) => (
            <GestureTrigger key={uri} onPress={() => openModal(index)}>
              <Pressable>
                <Image source={{ uri }} />
              </Pressable>
            </GestureTrigger>
          ))}
          <Modal transparent visible={visible}>
            <GestureViewer
              data={images}
              initialIndex={selectedIndex}
              renderItem={renderImage}
              ListComponent={ScrollView}
              onDismiss={() => setVisible(false)}
            />
            <View>
              <Button title="Prev" onPress={goToPrevious} />
              <Button title="Jump to index 2" onPress={() => goToIndex(2)} />
              <Button title="Next" onPress={goToNext} />
              <Text>{`${currentIndex + 1} / ${totalCount}`}</Text>
            </View>
          </Modal>
        </View>
      );
    }
    Tip

    contain 콘텐츠의 정확한 범위 정확한 줌과 팬 범위가 필요하다면 getItemDimensions로 콘텐츠의 원본 크기를 전달하거나, 이미지 로드 후 setItemDimensions로 등록하세요. 자세한 내용은 콘텐츠 크기 가이드를 참고하세요.