1- import React from 'react' ;
2- import { View , StyleSheet , Text , TouchableHighlight } from 'react-native' ;
1+ import React , { useState , useEffect } from 'react' ;
2+ import { View , ViewStyle , TextStyle , StyleSheet , Text , TouchableHighlight , TextInput } from 'react-native' ;
33import { containerStyle , containerSize , contentSize } from './DirText' ;
44import { size } from './index' ;
55import Button from '../Button' ;
@@ -11,10 +11,19 @@ export interface PageProps {
1111 totalPage : number ;
1212 renderPages ?: ( current : number , totalPage : number ) => React . ReactNode ;
1313 onCurrent ?: ( current : number , totalPage ?: number ) => unknown ;
14+ setCurrent : React . Dispatch < React . SetStateAction < number > > ;
15+ simple ?: boolean ;
1416}
1517
1618const Page = ( props : PageProps ) => {
17- const { size, currentColor, current, totalPage, renderPages, onCurrent } = props ;
19+ const { size, currentColor, current, totalPage, renderPages, onCurrent, setCurrent, simple } = props ;
20+
21+ useEffect ( ( ) => {
22+ setJumpCurrent ( String ( current ) ) ;
23+ } , [ current ] ) ;
24+ const [ jumpCurrent , setJumpCurrent ] = useState ( '1' ) ;
25+ const [ currentType , setJumpCurrentType ] = useState ( true ) ;
26+
1827 const textSize = size === 'small' ? 1 : 2 ;
1928 if ( renderPages ) {
2029 return (
@@ -30,7 +39,35 @@ const Page = (props: PageProps) => {
3039 { minWidth : containerSize [ size ] , height : containerSize [ size ] , borderWidth : 0 , flexShrink : 0 } ,
3140 ] }
3241 >
33- < Button bordered = { false } >
42+ { simple === true ? (
43+ < TextInput
44+ keyboardType = "number-pad"
45+ onBlur = { ( ) => {
46+ let newJumpCurrent = Number ( jumpCurrent ) ;
47+ if ( newJumpCurrent >= totalPage ) {
48+ setCurrent ( totalPage ) ;
49+ } else {
50+ setCurrent ( newJumpCurrent ) ;
51+ }
52+ } }
53+ onFocus = { ( ) => {
54+ setJumpCurrent ( '' ) ;
55+ } }
56+ blurOnSubmit = { true }
57+ onChangeText = { ( text ) => {
58+ setJumpCurrent ( text ) ;
59+ } }
60+ value = { jumpCurrent }
61+ style = { [
62+ styles . inputStyle ,
63+ {
64+ color : currentColor ?? '#46a6ff' ,
65+ fontSize : contentSize [ size ] ,
66+ lineHeight : contentSize [ size ] + textSize ,
67+ } ,
68+ ] }
69+ />
70+ ) : (
3471 < Text
3572 style = { {
3673 color : currentColor ?? '#46a6ff' ,
@@ -40,24 +77,34 @@ const Page = (props: PageProps) => {
4077 >
4178 { current }
4279 </ Text >
43- < Text
44- style = { {
45- color : currentColor ?? '#46a6ff' ,
46- fontSize : contentSize [ size ] - 1 ,
47- lineHeight : contentSize [ size ] - textSize ,
48- } }
49- >
50- /
51- </ Text >
52- < Text style = { { color : '#3d3d3d' , fontSize : contentSize [ size ] , lineHeight : contentSize [ size ] + textSize } } >
53- { totalPage }
54- </ Text >
55- </ Button >
80+ ) }
81+ < Text
82+ style = { {
83+ color : currentColor ?? '#46a6ff' ,
84+ fontSize : contentSize [ size ] - 1 ,
85+ lineHeight : contentSize [ size ] - textSize ,
86+ } }
87+ >
88+ /
89+ </ Text >
90+ < Text style = { { color : '#3d3d3d' , fontSize : contentSize [ size ] , lineHeight : contentSize [ size ] + textSize } } >
91+ { totalPage }
92+ </ Text >
5693 </ View >
5794 ) ;
5895} ;
5996
97+ export const inputStyle : ViewStyle | TextStyle = {
98+ height : 27 ,
99+ width : 33 ,
100+ borderColor : 'gray' ,
101+ borderWidth : 0.5 ,
102+ textAlign : 'center' ,
103+ padding : 2 ,
104+ marginHorizontal : 3 ,
105+ } ;
60106const styles = StyleSheet . create ( {
61107 containerStyle,
108+ inputStyle,
62109} ) ;
63110export default Page ;
0 commit comments