React Native

react native 뷰페이저 인디케이터

Machine_웅 2020. 8. 5. 18:12
728x90
반응형

 

https://www.npmjs.com/package/@react-native-community/viewpager

 

@react-native-community/viewpager

React Native ViewPager native view

www.npmjs.com

 

 

 

//인디케이터
    indicator(position){
        const {data} = this.state
        if(data.images == undefined){
            return(<View></View>)
        }else{
            return(
                <View style = {{ flexDirection:'row' }}>
                    {data.images.map((value,index) => 
                        <View style ={{
                            marginHorizontal:3,
                            width:10,
                            height:10,
                            backgroundColor: position == index ? 'white':'gray',
                            borderRadius:120
                            }}></View>
                    )}
                </View>
            )
        }
    }
<View style={{ margin: 15, width: width, aspectRatio: 16 / 9, backgroundColor: AppStyle.AppThemeColorGray }}>
                                                    <View style = {{flex:1,justifyContent:'flex-end'}}>
                                                        <ViewPager
                                                            style={{ flex: 1 }}
                                                            initialPage={0}
                                                            scrollEnabled={true}
                                                            orientation={"horizontal"}
                                                            onPageSelected = {(e) =>this.setState({image_position : e.nativeEvent.position})}
                                                        >
                                                            {data.images.map((value, index) =>
                                                                <View style={{ flex: 1 }}>
                                                                    <Image
                                                                        resizeMode ='contain'
                                                                        style={{ flex: 1, backgroundColor: 'black' }}
                                                                        source={{ uri: value }}
                                                                    />
                                                                </View>
                                                            )}
                                                        </ViewPager>

                                                        {/* 인디케이터  */}
                                                        <View style={{
                                                            width: 'auto',
                                                            height: 10,
                                                            backgroundColor:'transparent',
                                                            position: 'absolute',
                                                            alignSelf: 'center',
                                                            bottom: 10
                                                        }}>{this.indicator(image_position)}</View>
                                                    </View>
                                                </View>
728x90
반응형

'React Native' 카테고리의 다른 글

이슈 ) 파일 업로드시 [TypeError : Network request failed]  (0) 2020.08.12
자바스크립트 Map  (0) 2020.08.06
헤더 컴포넌트  (0) 2020.08.04
정규식 ) 돈 , 찍기  (0) 2020.08.03
(작성중 )react native 헤드리스 headless  (0) 2020.07.13