9
9
10
10
'use strict' ;
11
11
12
- import * as React from "react" ;
13
- import { Image ,
14
- StyleSheet ,
15
- Text ,
16
- View ,
17
- SafeAreaView ,
18
- } from 'react-native'
12
+ import * as React from 'react' ;
13
+ import { Image , StyleSheet , Text , View , SafeAreaView } from 'react-native' ;
19
14
20
15
import ViewPager from '@react-native-community/viewpager' ;
21
- import { PAGES , BGCOLOR , IMAGE_URIS , createPage } from "./utils" ;
22
- import { Button } from "./src/component/Button" ;
23
- import { LikeCount } from "./src/component/LikeCount" ;
24
- import { ProgressBar } from "./src/component/ProgressBar" ;
25
- import type { CreatePage } from "./utils"
26
- import type { PageScrollEvent , PageScrollState , PageScrollStateChangedEvent , PageSelectedEvent } from "../js" ;
16
+ import { PAGES , createPage } from './utils' ;
17
+ import { Button } from './src/component/Button' ;
18
+ import { LikeCount } from './src/component/LikeCount' ;
19
+ import { ProgressBar } from './src/component/ProgressBar' ;
20
+ import type { CreatePage } from './utils' ;
21
+ import type {
22
+ PageScrollEvent ,
23
+ PageScrollState ,
24
+ PageScrollStateChangedEvent ,
25
+ PageSelectedEvent ,
26
+ } from '../js' ;
27
27
28
28
type State = {
29
29
page : number ,
@@ -34,11 +34,10 @@ type State = {
34
34
offset : number ,
35
35
} ,
36
36
pages : Array < CreatePage > ,
37
- scrollState : PageScrollState
37
+ scrollState : PageScrollState ,
38
38
} ;
39
39
40
40
export default class ViewPagerExample extends React . Component < * , State > {
41
-
42
41
viewPager : React . Ref < typeof ViewPager > ;
43
42
44
43
constructor ( props : any ) {
@@ -58,28 +57,32 @@ export default class ViewPagerExample extends React.Component<*, State> {
58
57
offset : 0 ,
59
58
} ,
60
59
pages : pages ,
61
- scrollState : 'idle'
60
+ scrollState : 'idle' ,
62
61
} ;
63
62
this . viewPager = React . createRef ( ) ;
64
- } ;
63
+ }
65
64
66
65
onPageSelected = ( e : PageSelectedEvent ) = > {
67
66
this . setState ( { page : e . nativeEvent . position } ) ;
68
67
} ;
69
68
70
- onPageScroll = ( e : PageScrollEvent ) = > {
71
- this . setState ( { progress : {
72
- position : e . nativeEvent . position ,
73
- offset : e . nativeEvent . offset ,
74
- } } ) ;
69
+ onPageScroll = ( e : PageScrollEvent ) = > {
70
+ this . setState ( {
71
+ progress : {
72
+ position : e . nativeEvent . position ,
73
+ offset : e . nativeEvent . offset ,
74
+ } ,
75
+ } ) ;
75
76
} ;
76
77
77
78
onPageScrollStateChanged = ( e : PageScrollStateChangedEvent ) = > {
78
79
this . setState ( { scrollState : e . nativeEvent . pageScrollState } ) ;
79
80
} ;
80
81
81
82
addPage = ( ) = > {
82
- this . setState ( prevState => ( { pages : [ ...prevState . pages , createPage ( prevState . pages . length ) ] } ) ) ;
83
+ this . setState ( prevState => ( {
84
+ pages : [ ...prevState . pages , createPage ( prevState . pages . length ) ] ,
85
+ } ) ) ;
83
86
} ;
84
87
85
88
move = ( delta : number ) = > {
@@ -100,14 +103,11 @@ export default class ViewPagerExample extends React.Component<*, State> {
100
103
renderPage ( page : CreatePage ) {
101
104
return (
102
105
< View key = { page . key } style = { page . style } collapsable = { false } >
103
- < Image
104
- style = { styles . image }
105
- source = { page . imgSource }
106
- />
106
+ < Image style = { styles . image } source = { page . imgSource } />
107
107
< LikeCount />
108
108
</ View >
109
109
) ;
110
- } ;
110
+ }
111
111
112
112
render ( ) {
113
113
const { page, pages, animationsAreEnabled} = this . state ;
@@ -124,9 +124,9 @@ export default class ViewPagerExample extends React.Component<*, State> {
124
124
// Lib does not support dynamically orientation change
125
125
orientation = "horizontal"
126
126
// Lib does not support dynamically transitionStyle change
127
- transitionStyle = "scroll"
127
+ transitionStyle = "scroll"
128
128
ref = { this . viewPager } >
129
- { pages . map ( page => this . renderPage ( page ) ) }
129
+ { pages . map ( page => this . renderPage ( page ) ) }
130
130
</ ViewPager >
131
131
< View style = { styles . buttons } >
132
132
< Button
@@ -177,8 +177,15 @@ export default class ViewPagerExample extends React.Component<*, State> {
177
177
/>
178
178
</ View >
179
179
< View style = { styles . progress } >
180
- < Text style = { styles . buttonText } > Page { page + 1 } / { pages . length } </ Text >
181
- < ProgressBar numberOfPages = { pages . length } size = { 300 } progress = { this . state . progress } />
180
+ < Text style = { styles . buttonText } >
181
+ { ' ' }
182
+ Page { page + 1 } / { pages . length } { ' ' }
183
+ </ Text >
184
+ < ProgressBar
185
+ numberOfPages = { pages . length }
186
+ size = { 300 }
187
+ progress = { this . state . progress }
188
+ />
182
189
</ View >
183
190
</ SafeAreaView >
184
191
) ;
0 commit comments