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' ;
3
3
import { containerStyle , containerSize , contentSize } from './DirText' ;
4
4
import { size } from './index' ;
5
5
import Button from '../Button' ;
@@ -11,10 +11,19 @@ export interface PageProps {
11
11
totalPage : number ;
12
12
renderPages ?: ( current : number , totalPage : number ) => React . ReactNode ;
13
13
onCurrent ?: ( current : number , totalPage ?: number ) => unknown ;
14
+ setCurrent : React . Dispatch < React . SetStateAction < number > > ;
15
+ simple ?: boolean ;
14
16
}
15
17
16
18
const 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
+
18
27
const textSize = size === 'small' ? 1 : 2 ;
19
28
if ( renderPages ) {
20
29
return (
@@ -30,7 +39,35 @@ const Page = (props: PageProps) => {
30
39
{ minWidth : containerSize [ size ] , height : containerSize [ size ] , borderWidth : 0 , flexShrink : 0 } ,
31
40
] }
32
41
>
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
+ ) : (
34
71
< Text
35
72
style = { {
36
73
color : currentColor ?? '#46a6ff' ,
@@ -40,24 +77,34 @@ const Page = (props: PageProps) => {
40
77
>
41
78
{ current }
42
79
</ 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 >
56
93
</ View >
57
94
) ;
58
95
} ;
59
96
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
+ } ;
60
106
const styles = StyleSheet . create ( {
61
107
containerStyle,
108
+ inputStyle,
62
109
} ) ;
63
110
export default Page ;
0 commit comments