Skip to content

Commit 00428b9

Browse files
Amber-Nan杨楠
andauthored
feat(Pagination): 增加页码跳转功能 & 更新文档 (#319)
* fix:发布 iOS 应用商店:一. 创建AppID * fix:发布 iOS 应用商店优化排版 * fix:ios应用商店文档更新及排版优化 * fix:修改环境安装文档语法错误及部分内容优化 * fix:更新ios应用发布流程 * fix:ios应用商店发布更新 * fix:更新ios及安卓应用商店发布 * fix:安卓上架更新 * fix:增加button自定义文本实例 * fix:增加checkBox复选框size调整及文档描述效果展示 * doc:更新文档导入图片 * doc(website): Update Readme.md * fix:修复SpeedDial Android 点击事件失效及拖拽失效问题 #286 * fix:解决SelectCascader 在安卓端不能选择问题 #289 * fix:修复Modal 弹出动画底层延迟收起问题 * feat:NoticeBar 通告栏增加文字样式修改及页面demo展示 * doc(website): Update NoticeBar Readme.md * fix:解决 MenuDropdown 安卓下拉菜单被遮挡问题 * feat:Progress 新增进度图标 * doc(website): Update Progress Readme.md * style:删除多余代码 * feat:Progress 增加进度提示字展示 及 doc(website): Update Progress Readme.md * feat:Ellipsis 增加弹出展示全部文本内容 * fix:解决 Ellipsis 报错问题 * style:Update local code * fix:解决 NoticeBar首次渲染报错问题 * fix:SwipeAction 增加key * doc(website): Update Readme.md * doc(website): Update Readme.md * feat:Pagination 增加页码跳转功能 * feat:Pagination 增加页码跳转功能 及 doc(website): Update Pagination Readme.md Co-authored-by: 杨楠 <yangnan@nihaosi.com>
1 parent da4dbf3 commit 00428b9

File tree

4 files changed

+142
-10
lines changed

4 files changed

+142
-10
lines changed

example/examples/src/routes/Pagination/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ export default class Index extends Component<IndexProps, IndexState> {
4343
/>
4444
</View>
4545
</Card>
46+
<Card title="使用跳转页码">
47+
<View style={{paddingHorizontal: 20}}>
48+
<Pagination
49+
icon
50+
jumpBtn={true}
51+
current={this.state.current1}
52+
total={50}
53+
pageSize={20}
54+
onPageChange={(type, current1) => {
55+
this.setState({current1});
56+
}}
57+
/>
58+
</View>
59+
</Card>
4660
<Card title="使用icon">
4761
<View style={{paddingHorizontal: 20}}>
4862
<Pagination
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React, { useRef, useState, useEffect } from 'react';
2+
import { View, ViewStyle, TextStyle, StyleSheet, Text, TextInput } from 'react-native';
3+
import Icon from '../Icon';
4+
import Button from '../Button';
5+
import { size } from './index';
6+
import { number } from 'prop-types';
7+
8+
export enum containerSize {
9+
small = 30,
10+
default = 36,
11+
large = 44,
12+
}
13+
export enum contentSize {
14+
small = 12,
15+
default = 18,
16+
large = 26,
17+
}
18+
export interface MoreDirProps {
19+
size: size;
20+
borderColor?: string;
21+
color?: string;
22+
setCurrent: React.Dispatch<React.SetStateAction<number>>;
23+
current: number;
24+
}
25+
26+
const MoreDir = (props: MoreDirProps) => {
27+
const { size, borderColor = '#8d8d8d', color, setCurrent, current } = props;
28+
const [jumpCurrent, setJumpCurrent] = useState(1);
29+
30+
return (
31+
<View style={styles.containerStyle}>
32+
<Text>跳至</Text>
33+
<TextInput
34+
keyboardType="numeric"
35+
onSubmitEditing={() => {
36+
setCurrent(Number(jumpCurrent));
37+
}}
38+
onBlur={() => {
39+
setCurrent(Number(jumpCurrent));
40+
}}
41+
blurOnSubmit={true}
42+
onChangeText={(text) => {
43+
let textCurrent: number = Number(text);
44+
if (textCurrent >= current) {
45+
setJumpCurrent(current);
46+
} else if (textCurrent < current) {
47+
setJumpCurrent(textCurrent);
48+
}
49+
}}
50+
style={styles.inputStyle}
51+
/>
52+
<Text></Text>
53+
</View>
54+
);
55+
};
56+
57+
export const containerStyle: ViewStyle = {
58+
flexDirection: 'row',
59+
justifyContent: 'center',
60+
alignItems: 'center',
61+
marginLeft: 5,
62+
};
63+
export const inputStyle: ViewStyle | TextStyle = {
64+
height: 27,
65+
width: 33,
66+
borderColor: 'gray',
67+
borderWidth: 0.5,
68+
textAlign: 'center',
69+
padding: 2,
70+
marginHorizontal: 3,
71+
};
72+
const styles = StyleSheet.create({
73+
containerStyle,
74+
inputStyle,
75+
});
76+
export default MoreDir;

packages/core/src/Pagination/README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Pagination 分页器
33

44
用于展示页码、请求数据等。
55

6-
<img src='https://user-images.githubusercontent.com/66067296/139399708-239e65f9-565e-4be2-9497-c8e5b836cef6.png' alt='Pagination' style='zoom:33%;' />
6+
<img src='https://user-images.githubusercontent.com/66067296/140001996-ff0fe66c-0482-4576-9f19-11be3a6b7ada.png' alt='Pagination' style='zoom:33%;' />
77

88
### 基础示例
99

@@ -43,6 +43,31 @@ function Demo() {
4343
current={current}
4444
total={60}
4545
pageSize={8}
46+
jumpBtn={true}
47+
onPageChange={(type, current) => {
48+
setCurrent(current)
49+
console.log('type, current: ', type, current);
50+
}}
51+
/>
52+
</Fragment>
53+
);
54+
}
55+
```
56+
57+
### 页码跳转
58+
59+
```jsx
60+
import { Fragment, useState } from 'react';
61+
import { Pagination } from '@uiw/react-native';
62+
function Demo() {
63+
const [current, setCurrent] = useState(false)
64+
return (
65+
<Fragment>
66+
<Pagination
67+
current={current}
68+
total={60}
69+
pageSize={8}
70+
jumpBtn={true}
4671
onPageChange={(type, current) => {
4772
setCurrent(current)
4873
console.log('type, current: ', type, current);
@@ -79,5 +104,7 @@ export interface PaginationProps {
79104
borderColor?: string
80105
/** 按钮中的颜色 */
81106
color?: string
107+
/** 页码跳转 */
108+
jumpBtn?: boolean;
82109
}
83110
```

packages/core/src/Pagination/index.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { View, StyleSheet } from 'react-native';
33
import DirText from './DirText';
4+
import MoreDir from './MoreDir';
45
import Page from './Page';
56

67
export type size = 'small' | 'default' | 'large';
@@ -28,12 +29,15 @@ export interface PaginationProps {
2829
borderColor?: string;
2930
/** 按钮中的颜色 */
3031
color?: string;
32+
/** 页码跳转 */
33+
jumpBtn?: boolean;
3134
}
3235

3336
const Pagination = (props: PaginationProps) => {
3437
const {
3538
size = 'default',
3639
icon = false,
40+
jumpBtn = false,
3741
currentColor,
3842
total,
3943
pageSize = 10,
@@ -81,15 +85,26 @@ const Pagination = (props: PaginationProps) => {
8185
totalPage={Math.ceil(total / pageSize)}
8286
currentColor={currentColor}
8387
/>
84-
<DirText
85-
onPageChange={onPageChange}
86-
size={size}
87-
direction="right"
88-
disabled={current === Math.ceil(total / pageSize)}
89-
icon={icon}
90-
borderColor={borderColor}
91-
color={color}
92-
/>
88+
<View style={{ flexDirection: 'row' }}>
89+
<DirText
90+
onPageChange={onPageChange}
91+
size={size}
92+
direction="right"
93+
disabled={current === Math.ceil(total / pageSize)}
94+
icon={icon}
95+
borderColor={borderColor}
96+
color={color}
97+
/>
98+
{jumpBtn === true && (
99+
<MoreDir
100+
setCurrent={setCurrent}
101+
size={size}
102+
current={Math.ceil(total / pageSize)}
103+
borderColor={borderColor}
104+
color={color}
105+
/>
106+
)}
107+
</View>
93108
</View>
94109
);
95110
};

0 commit comments

Comments
 (0)