-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { View } from 'react-native'; | ||
|
||
interface SiglePageProps { | ||
children: React.ReactElement; | ||
contentSize: number; | ||
} | ||
|
||
const SiglePage: React.FC<SiglePageProps> = (props) => { | ||
const { children, contentSize } = props; | ||
return <View style={{ width: contentSize }}>{children}</View>; | ||
}; | ||
|
||
export default SiglePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { Dimensions } from 'react-native'; | ||
import { PageViewProps, PageViewVerifyProps } from './type'; | ||
|
||
const { width } = Dimensions.get('window'); | ||
|
||
export const useVerifyProps = (props: PageViewProps): PageViewVerifyProps => { | ||
const { children, style } = props; | ||
const pageSize = React.Children.count(children); | ||
if (pageSize === 0) { | ||
throw new Error('PageView must be contains at least one chid'); | ||
} | ||
let contentSize: number = width; | ||
if (style && style.width) { | ||
if (typeof style.width === 'number') { | ||
contentSize = style.width; | ||
} else { | ||
throw new Error('PageView width only support number'); | ||
} | ||
} | ||
|
||
const snapPoints = new Array(pageSize) | ||
.fill(0) | ||
.map((_, index) => -index * contentSize); | ||
|
||
return { | ||
...props, | ||
pageSize, | ||
contentSize, | ||
snapPoints, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ViewStyle } from 'react-native'; | ||
|
||
export interface PageViewProps { | ||
children: React.ReactElement; | ||
|
||
style?: ViewStyle; | ||
initialPage?: number; | ||
scrollEnabled?: boolean; | ||
bounces?: boolean; | ||
gestureBack?: boolean; | ||
|
||
onPageScroll?: (translate: number) => void; | ||
onPageSelected?: (currentPage: number) => void; | ||
onPageScrollStateChanged?: (state: PageStateType) => void; | ||
} | ||
|
||
export interface PageViewRef { | ||
setPage: (index: number) => void; | ||
setPageWithoutAnimation: (index: number) => void; | ||
getCurrentPage: () => number; | ||
} | ||
|
||
export const DURATION = 350; | ||
|
||
export type PageStateType = 'dragging' | 'settling' | 'idle'; | ||
|
||
export interface PageViewVerifyProps extends PageViewProps { | ||
pageSize: number; | ||
contentSize: number; | ||
snapPoints: number[]; | ||
} |