ipanel-rnapp-ajb-base 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/App.js +3 -0
- package/app/components/common/PickerV1/index.js +93 -0
- package/app/components/common/PickerV2/index.js +96 -0
- package/app/components/common/PickerV2Base/_util/devWarning.tsx +5 -0
- package/app/components/common/PickerV2Base/_util/getLocale.tsx +42 -0
- package/app/components/common/PickerV2Base/_util/hooks/useAnimations.tsx +57 -0
- package/app/components/common/PickerV2Base/_util/hooks/useClickAway.ts +30 -0
- package/app/components/common/PickerV2Base/_util/isPromise.ts +5 -0
- package/app/components/common/PickerV2Base/_util/reactNode.ts +27 -0
- package/app/components/common/PickerV2Base/_util/version.json +1 -0
- package/app/components/common/PickerV2Base/_util/with-default-props.tsx +15 -0
- package/app/components/common/PickerV2Base/config-provider/DisabledContext.tsx +24 -0
- package/app/components/common/PickerV2Base/config-provider/index.tsx +7 -0
- package/app/components/common/PickerV2Base/locale-provider/en_US.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/es_ES.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/fa_IR.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/index.en-US.md +37 -0
- package/app/components/common/PickerV2Base/locale-provider/index.tsx +126 -0
- package/app/components/common/PickerV2Base/locale-provider/index.zh-CN.md +38 -0
- package/app/components/common/PickerV2Base/locale-provider/ko_KR.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/pt_BR.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/ru_RU.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/sv_SE.tsx +22 -0
- package/app/components/common/PickerV2Base/locale-provider/useLocale.tsx +36 -0
- package/app/components/common/PickerV2Base/locale-provider/zh_CN.tsx +22 -0
- package/app/components/common/PickerV2Base/picker/Picker.tsx +216 -0
- package/app/components/common/PickerV2Base/picker/Popup.tsx +77 -0
- package/app/components/common/PickerV2Base/picker/PopupPickerTypes.tsx +16 -0
- package/app/components/common/PickerV2Base/picker/PropsType.tsx +26 -0
- package/app/components/common/PickerV2Base/picker/index.en-US.md +98 -0
- package/app/components/common/PickerV2Base/picker/index.tsx +85 -0
- package/app/components/common/PickerV2Base/picker/index.zh-CN.md +97 -0
- package/app/components/common/PickerV2Base/picker/locale/en_US.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/es_ES.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/fa_IR.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/id_ID.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/ko_KR.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/pt_BR.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/ru_RU.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/sv_SE.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/locale/zh_CN.tsx +5 -0
- package/app/components/common/PickerV2Base/picker/style/index.tsx +57 -0
- package/app/components/common/PickerV2Base/picker-view/PropsType.tsx +37 -0
- package/app/components/common/PickerV2Base/picker-view/Wheel.tsx +200 -0
- package/app/components/common/PickerV2Base/picker-view/columns-extend.tsx +86 -0
- package/app/components/common/PickerV2Base/picker-view/index.en-US.md +71 -0
- package/app/components/common/PickerV2Base/picker-view/index.tsx +69 -0
- package/app/components/common/PickerV2Base/picker-view/index.zh-CN.md +72 -0
- package/app/components/common/PickerV2Base/picker-view/picker-view.tsx +166 -0
- package/app/components/common/PickerV2Base/picker-view/style/index.tsx +51 -0
- package/app/components/common/PickerV2Base/style/index.tsx +96 -0
- package/app/components/common/PickerV2Base/style/themes/default.tsx +203 -0
- package/app/components/index.js +2 -0
- package/app/eventBus/index.js +1 -0
- package/app/hooks/shopMessageManager.js +5 -3
- package/app/screens/LoginScreen/OpenLogSheet.js +6 -1
- package/app/utils/common.js +0 -1
- package/package.json +19 -19
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Components
|
|
3
|
+
title: Provider
|
|
4
|
+
subtitle: 国际化和皮肤配置
|
|
5
|
+
type: Other
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
为组件内建文案提供统一的国际化支持。
|
|
9
|
+
|
|
10
|
+
## 使用
|
|
11
|
+
|
|
12
|
+
Provider 使用 React 的 [context](https://facebook.github.io/react/docs/context.html) 特性,只需在应用外围包裹一次即可全局生效。
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import enUS from '@ant-design/react-native/lib/locale-provider/en_US';
|
|
17
|
+
|
|
18
|
+
...
|
|
19
|
+
|
|
20
|
+
return <Provider locale={enUS}><App /></Provider>;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
我们暂时只提供英语,中文两种语言支持(`默认语言是中文`),所有语言包可以在 [这里](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider/) 找到。
|
|
24
|
+
|
|
25
|
+
### 增加语言包
|
|
26
|
+
|
|
27
|
+
如果你找不到你需要的语言包,欢迎你在 [英文语言包](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider/en_US.tsx) 的基础上创建一个新的语言包,并给我们 Pull Request。
|
|
28
|
+
|
|
29
|
+
### 其他国际化需求
|
|
30
|
+
|
|
31
|
+
本模块仅用于组件的内建文案,若有业务文案的国际化需求,建议使用 [react-intl](https://github.com/yahoo/react-intl),可参考示例:[Intl demo 1](http://github.com/ant-design/intl-example) 和 [Intl demo 2](http://yiminghe.me/learning-react/examples/react-intl.html?locale=en-US)。
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
36
|
+
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ------ |
|
|
37
|
+
| locale | 语言包配置,语言包可到 `@ant-design/react-native/lib/locale-provider/` 目录下寻找 | object | - |
|
|
38
|
+
| theme | 主题样式配置,可根据需要覆盖部分或者全部变量,具体变量请查看 [theme](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx) | object | - |
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/ko_KR'
|
|
2
|
+
import DatePicker from '../date-picker/locale/ko_KR'
|
|
3
|
+
import Form from '../form/locale/ko_KR'
|
|
4
|
+
import InputItem from '../input-item/locale/ko_KR'
|
|
5
|
+
import ListView from '../list-view/locale/ko_KR'
|
|
6
|
+
import Modal from '../modal/locale/ko_KR'
|
|
7
|
+
import Pagination from '../pagination/locale/ko_KR'
|
|
8
|
+
import Picker from '../picker/locale/ko_KR'
|
|
9
|
+
import SearchBar from '../search-bar/locale/ko_KR'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'ko_KR',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/pt_BR'
|
|
2
|
+
import DatePicker from '../date-picker/locale/pt_BR'
|
|
3
|
+
import Form from '../form/locale/pt_BR'
|
|
4
|
+
import InputItem from '../input-item/locale/pt_BR'
|
|
5
|
+
import ListView from '../list-view/locale/pt_BR'
|
|
6
|
+
import Modal from '../modal/locale/pt_BR'
|
|
7
|
+
import Pagination from '../pagination/locale/pt_BR'
|
|
8
|
+
import Picker from '../picker/locale/pt_BR'
|
|
9
|
+
import SearchBar from '../search-bar/locale/pt_BR'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'pt_BR',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/ru_RU'
|
|
2
|
+
import DatePicker from '../date-picker/locale/ru_RU'
|
|
3
|
+
import Form from '../form/locale/ru_RU'
|
|
4
|
+
import InputItem from '../input-item/locale/ru_RU'
|
|
5
|
+
import ListView from '../list-view/locale/ru_RU'
|
|
6
|
+
import Modal from '../modal/locale/ru_RU'
|
|
7
|
+
import Pagination from '../pagination/locale/ru_RU'
|
|
8
|
+
import Picker from '../picker/locale/ru_RU'
|
|
9
|
+
import SearchBar from '../search-bar/locale/ru_RU'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'ru',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/sv_SE'
|
|
2
|
+
import DatePicker from '../date-picker/locale/sv_SE'
|
|
3
|
+
import Form from '../form/locale/sv_SE'
|
|
4
|
+
import InputItem from '../input-item/locale/sv_SE'
|
|
5
|
+
import ListView from '../list-view/locale/sv_SE'
|
|
6
|
+
import Modal from '../modal/locale/sv_SE'
|
|
7
|
+
import Pagination from '../pagination/locale/sv_SE'
|
|
8
|
+
import Picker from '../picker/locale/sv_SE'
|
|
9
|
+
import SearchBar from '../search-bar/locale/sv_SE'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'sv',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Locale } from '.'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { LocaleContext } from './index'
|
|
5
|
+
import defaultLocaleData from './zh_CN'
|
|
6
|
+
|
|
7
|
+
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>
|
|
8
|
+
|
|
9
|
+
const useLocale = <C extends LocaleComponentName = LocaleComponentName>(
|
|
10
|
+
componentName: C,
|
|
11
|
+
defaultLocale?: Locale[C] | (() => Locale[C]),
|
|
12
|
+
): readonly [NonNullable<Locale[C]>, string] => {
|
|
13
|
+
const fullLocale = React.useContext(LocaleContext)
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const getLocale = React.useMemo<NonNullable<Locale[C]>>(() => {
|
|
16
|
+
const locale = defaultLocale || defaultLocaleData[componentName]
|
|
17
|
+
const localeFromContext = fullLocale?.antLocale?.[componentName] ?? {}
|
|
18
|
+
return {
|
|
19
|
+
...(typeof locale === 'function' ? locale() : locale),
|
|
20
|
+
...(localeFromContext || {}),
|
|
21
|
+
}
|
|
22
|
+
}, [componentName, defaultLocale, fullLocale])
|
|
23
|
+
|
|
24
|
+
const getLocaleCode = React.useMemo<string>(() => {
|
|
25
|
+
const localeCode = fullLocale?.antLocale?.locale
|
|
26
|
+
// Had use LocaleProvide but didn't set locale
|
|
27
|
+
if (fullLocale?.antLocale.exist && !localeCode) {
|
|
28
|
+
return defaultLocaleData.locale
|
|
29
|
+
}
|
|
30
|
+
return localeCode!
|
|
31
|
+
}, [fullLocale])
|
|
32
|
+
|
|
33
|
+
return [getLocale, getLocaleCode] as const
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default useLocale
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/zh_CN'
|
|
2
|
+
import DatePicker from '../date-picker/locale/zh_CN'
|
|
3
|
+
import Form from '../form/locale/zh_CN'
|
|
4
|
+
import InputItem from '../input-item/locale/zh_CN'
|
|
5
|
+
import ListView from '../list-view/locale/zh_CN'
|
|
6
|
+
import Modal from '../modal/locale/zh_CN'
|
|
7
|
+
import Pagination from '../pagination/locale/zh_CN'
|
|
8
|
+
import Picker from '../picker/locale/zh_CN'
|
|
9
|
+
import SearchBar from '../search-bar/locale/zh_CN'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'zh_CN',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import useMergedState from 'rc-util/lib/hooks/useMergedState'
|
|
2
|
+
import React, {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useImperativeHandle,
|
|
8
|
+
useMemo,
|
|
9
|
+
useState,
|
|
10
|
+
} from 'react'
|
|
11
|
+
import { Omit } from 'utility-types'
|
|
12
|
+
|
|
13
|
+
import { Keyboard } from 'react-native'
|
|
14
|
+
import { getComponentLocale } from '../_util/getLocale'
|
|
15
|
+
import DisabledContext from '../config-provider/DisabledContext'
|
|
16
|
+
import { LocaleContext } from '../locale-provider'
|
|
17
|
+
import { PickerColumn, PickerValue } from '../picker-view/PropsType'
|
|
18
|
+
import RMCPickerView from '../picker-view/picker-view'
|
|
19
|
+
import { useTheme } from '../style'
|
|
20
|
+
import PopupPicker from './Popup'
|
|
21
|
+
import { PickerPropsType } from './PropsType'
|
|
22
|
+
import PickerStyles from './style'
|
|
23
|
+
|
|
24
|
+
export type PickerActions = {
|
|
25
|
+
open: () => void
|
|
26
|
+
close: () => void
|
|
27
|
+
toggle: () => void
|
|
28
|
+
value?: PickerValue[]
|
|
29
|
+
}
|
|
30
|
+
export type PickerRef = PickerActions
|
|
31
|
+
|
|
32
|
+
export interface RMCPickerProps
|
|
33
|
+
extends Omit<PickerPropsType, 'value' | 'data' | 'cols' | 'cascade'> {
|
|
34
|
+
value?: PickerValue[]
|
|
35
|
+
innerValue: PickerValue[]
|
|
36
|
+
columns: PickerColumn[]
|
|
37
|
+
handleSelect: (value: PickerValue, index: number) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const RMCPicker = forwardRef<PickerRef, RMCPickerProps>((props, ref) => {
|
|
41
|
+
const contextDisabled = useContext(DisabledContext)
|
|
42
|
+
const {
|
|
43
|
+
onVisibleChange,
|
|
44
|
+
visible,
|
|
45
|
+
children,
|
|
46
|
+
okText,
|
|
47
|
+
dismissText,
|
|
48
|
+
okButtonProps,
|
|
49
|
+
dismissButtonProps,
|
|
50
|
+
onChange,
|
|
51
|
+
onOk,
|
|
52
|
+
onDismiss,
|
|
53
|
+
onClose,
|
|
54
|
+
title,
|
|
55
|
+
extra,
|
|
56
|
+
disabled = contextDisabled,
|
|
57
|
+
format,
|
|
58
|
+
value,
|
|
59
|
+
innerValue,
|
|
60
|
+
columns,
|
|
61
|
+
handleSelect,
|
|
62
|
+
...restProps
|
|
63
|
+
} = props
|
|
64
|
+
|
|
65
|
+
const [innerVisible, setInnerVisible2] = useMergedState<boolean>(false, {
|
|
66
|
+
value: visible,
|
|
67
|
+
onChange: (v) => onVisibleChange?.(v),
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const setInnerVisible = useCallback(
|
|
71
|
+
(bool) => {
|
|
72
|
+
!disabled && setInnerVisible2(bool)
|
|
73
|
+
},
|
|
74
|
+
[disabled, setInnerVisible2],
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
Keyboard.dismiss()
|
|
79
|
+
}, [innerVisible])
|
|
80
|
+
|
|
81
|
+
// ================== Actions Ref ==================
|
|
82
|
+
const actions = useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
toggle: () => {
|
|
85
|
+
setInnerVisible(!innerVisible)
|
|
86
|
+
},
|
|
87
|
+
open: () => {
|
|
88
|
+
setInnerVisible(true)
|
|
89
|
+
},
|
|
90
|
+
close: () => {
|
|
91
|
+
setInnerVisible(false)
|
|
92
|
+
onClose?.()
|
|
93
|
+
},
|
|
94
|
+
value: innerValue,
|
|
95
|
+
}),
|
|
96
|
+
[innerValue, innerVisible, onClose, setInnerVisible],
|
|
97
|
+
)
|
|
98
|
+
useImperativeHandle(ref, () => actions)
|
|
99
|
+
|
|
100
|
+
const handleOk = useCallback(() => {
|
|
101
|
+
const extend = columns.map(
|
|
102
|
+
(column, index) =>
|
|
103
|
+
column.find((item) => item.value === innerValue?.[index]) ?? column[0],
|
|
104
|
+
)
|
|
105
|
+
const nextValue = extend.map((item) => item.value)
|
|
106
|
+
onOk?.(nextValue, { items: extend, columns })
|
|
107
|
+
onChange?.(nextValue, { items: extend, columns })
|
|
108
|
+
actions.close()
|
|
109
|
+
}, [actions, columns, onChange, onOk, innerValue])
|
|
110
|
+
|
|
111
|
+
const handleDismiss = useCallback(() => {
|
|
112
|
+
onDismiss?.()
|
|
113
|
+
actions.close()
|
|
114
|
+
}, [actions, onDismiss])
|
|
115
|
+
|
|
116
|
+
const _locale = getComponentLocale(
|
|
117
|
+
props,
|
|
118
|
+
useContext(LocaleContext),
|
|
119
|
+
'Picker',
|
|
120
|
+
() => require('./locale/zh_CN'),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
// ================== Extra Render ==================
|
|
124
|
+
const [innerExtra, setInnerExtra] = useState(extra || _locale.extra)
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!children || innerVisible) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
if (!value?.length) {
|
|
130
|
+
return setInnerExtra(extra || _locale.extra)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setInnerExtra(
|
|
134
|
+
format?.(
|
|
135
|
+
columns.reduce((cur: any[], next, index) => {
|
|
136
|
+
const labelValue = next.find((item) => item.value === value[index])
|
|
137
|
+
if (labelValue?.label) {
|
|
138
|
+
cur.push(labelValue.label)
|
|
139
|
+
}
|
|
140
|
+
return cur
|
|
141
|
+
}, []),
|
|
142
|
+
),
|
|
143
|
+
)
|
|
144
|
+
}, [value, columns, innerVisible, format, children, extra, _locale.extra])
|
|
145
|
+
|
|
146
|
+
const renderChildren = () => {
|
|
147
|
+
if (!children) {
|
|
148
|
+
return null
|
|
149
|
+
}
|
|
150
|
+
// children as function
|
|
151
|
+
if (typeof children === 'function') {
|
|
152
|
+
return children({
|
|
153
|
+
value,
|
|
154
|
+
extra: innerExtra || extra || _locale.extra,
|
|
155
|
+
disabled,
|
|
156
|
+
toggle: actions.toggle,
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
const child = children as React.ReactElement
|
|
160
|
+
const newChildProps = {
|
|
161
|
+
value,
|
|
162
|
+
extra: innerExtra || extra || _locale.extra,
|
|
163
|
+
disabled,
|
|
164
|
+
} as any
|
|
165
|
+
if (!disabled) {
|
|
166
|
+
newChildProps[props.triggerType!] = (e: any) => {
|
|
167
|
+
if (child.props[props.triggerType!]) {
|
|
168
|
+
child.props[props.triggerType!](e)
|
|
169
|
+
}
|
|
170
|
+
actions.toggle()
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return React.cloneElement(child as any, newChildProps)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const styles = useTheme({
|
|
177
|
+
styles: props.styles,
|
|
178
|
+
themeStyles: PickerStyles,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<>
|
|
183
|
+
<PopupPicker
|
|
184
|
+
styles={styles}
|
|
185
|
+
visible={innerVisible}
|
|
186
|
+
title={title}
|
|
187
|
+
okText={okText || _locale.okText}
|
|
188
|
+
onOk={handleOk}
|
|
189
|
+
dismissText={dismissText || _locale.dismissText}
|
|
190
|
+
onDismiss={handleDismiss}
|
|
191
|
+
onClose={actions.close}
|
|
192
|
+
okButtonProps={okButtonProps}
|
|
193
|
+
dismissButtonProps={dismissButtonProps}>
|
|
194
|
+
{/* TODO: 组件卸载是在visible更新fasle之后,需要前置 */}
|
|
195
|
+
{/* 否则会无效执行onPickerChange */}
|
|
196
|
+
{innerVisible && (
|
|
197
|
+
<RMCPickerView
|
|
198
|
+
{...restProps}
|
|
199
|
+
value={innerValue}
|
|
200
|
+
columns={columns}
|
|
201
|
+
handleSelect={handleSelect}
|
|
202
|
+
/>
|
|
203
|
+
)}
|
|
204
|
+
</PopupPicker>
|
|
205
|
+
{renderChildren()}
|
|
206
|
+
</>
|
|
207
|
+
)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
RMCPicker.displayName = 'Picker'
|
|
211
|
+
RMCPicker.defaultProps = {
|
|
212
|
+
triggerType: 'onPress',
|
|
213
|
+
format: (labels: string[]) => labels.join(','),
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default RMCPicker
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { memo } from 'react'
|
|
2
|
+
import { Text, TouchableHighlight, View,Modal,TouchableOpacity } from 'react-native'
|
|
3
|
+
// import Modal from '../modal/ModalView'
|
|
4
|
+
import { PopupPickerProps } from './PopupPickerTypes'
|
|
5
|
+
|
|
6
|
+
const PopupPicker = memo((props: PopupPickerProps) => {
|
|
7
|
+
const {
|
|
8
|
+
styles,
|
|
9
|
+
title,
|
|
10
|
+
okText = 'Ok',
|
|
11
|
+
dismissText = 'Dismiss',
|
|
12
|
+
visible,
|
|
13
|
+
onDismiss,
|
|
14
|
+
onOk,
|
|
15
|
+
onClose,
|
|
16
|
+
children,
|
|
17
|
+
} = props
|
|
18
|
+
|
|
19
|
+
const titleEl =
|
|
20
|
+
typeof title === 'string' ? (
|
|
21
|
+
<Text style={[styles.title]}>{title}</Text>
|
|
22
|
+
) : (
|
|
23
|
+
title
|
|
24
|
+
)
|
|
25
|
+
const okEl =
|
|
26
|
+
typeof okText === 'string' ? (
|
|
27
|
+
<View style={styles.okView}>
|
|
28
|
+
<Text style={[styles.actionText, styles.okText]}>{okText}</Text>
|
|
29
|
+
</View>
|
|
30
|
+
) : (
|
|
31
|
+
okText
|
|
32
|
+
)
|
|
33
|
+
const dismissEl =
|
|
34
|
+
typeof dismissText === 'string' ? (
|
|
35
|
+
<View style={styles.dismissView}>
|
|
36
|
+
<Text style={[styles.actionText, styles.dismissText]}>{dismissText}</Text>
|
|
37
|
+
</View>
|
|
38
|
+
) : (
|
|
39
|
+
dismissText
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Modal
|
|
44
|
+
animationType="none"
|
|
45
|
+
transparent={true}
|
|
46
|
+
visible={visible}
|
|
47
|
+
onRequestClose={onClose}>
|
|
48
|
+
<TouchableOpacity
|
|
49
|
+
style={[{position:'absolute',top:0,left:0,right:0,bottom:0,zIndex:999},styles.maskColor]}
|
|
50
|
+
onPress={onClose}
|
|
51
|
+
></TouchableOpacity>
|
|
52
|
+
<View style={{position:'absolute',left:0,right:0,bottom:0,zIndex:1000}}>
|
|
53
|
+
{children}
|
|
54
|
+
<View style={[styles.header]}>
|
|
55
|
+
<TouchableHighlight
|
|
56
|
+
onPress={onDismiss}
|
|
57
|
+
style={[styles.headerItem]}
|
|
58
|
+
activeOpacity={1}
|
|
59
|
+
underlayColor="#ddd"
|
|
60
|
+
{...props.dismissButtonProps}>
|
|
61
|
+
{dismissEl}
|
|
62
|
+
</TouchableHighlight>
|
|
63
|
+
<View style={[styles.headerItem]}>{titleEl}</View>
|
|
64
|
+
<TouchableHighlight
|
|
65
|
+
onPress={onOk}
|
|
66
|
+
style={[styles.headerItem]}
|
|
67
|
+
activeOpacity={1}
|
|
68
|
+
underlayColor="#ddd"
|
|
69
|
+
{...props.okButtonProps}>
|
|
70
|
+
{okEl}
|
|
71
|
+
</TouchableHighlight>
|
|
72
|
+
</View>
|
|
73
|
+
</View>
|
|
74
|
+
</Modal>
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
export default PopupPicker
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { TouchableHighlightProps } from 'react-native'
|
|
3
|
+
|
|
4
|
+
export type PopupPickerProps = {
|
|
5
|
+
onOk?: () => void
|
|
6
|
+
onDismiss?: () => void
|
|
7
|
+
onClose?: () => void
|
|
8
|
+
title?: ReactNode
|
|
9
|
+
visible?: boolean
|
|
10
|
+
okText?: ReactNode
|
|
11
|
+
dismissText?: ReactNode
|
|
12
|
+
okButtonProps?: TouchableHighlightProps
|
|
13
|
+
dismissButtonProps?: TouchableHighlightProps
|
|
14
|
+
children?: ReactNode
|
|
15
|
+
styles: any
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { Omit } from 'utility-types'
|
|
3
|
+
import {
|
|
4
|
+
PickerValue,
|
|
5
|
+
PickerValueExtend,
|
|
6
|
+
PickerViewPropsType,
|
|
7
|
+
} from '../picker-view/PropsType'
|
|
8
|
+
import { PickerViewStyle } from '../picker-view/style'
|
|
9
|
+
import { WithThemeStyles } from '../style'
|
|
10
|
+
import { PopupPickerProps } from './PopupPickerTypes'
|
|
11
|
+
import { PickerStyle } from './style'
|
|
12
|
+
|
|
13
|
+
export interface PickerPropsType
|
|
14
|
+
extends PickerViewPropsType,
|
|
15
|
+
WithThemeStyles<PickerViewStyle & PickerStyle>,
|
|
16
|
+
Omit<PopupPickerProps, 'onOk' | 'styles'> {
|
|
17
|
+
onOk?: (value: PickerValue[], extend: PickerValueExtend) => void
|
|
18
|
+
onPickerChange?: (value: PickerValue[], index: number) => void
|
|
19
|
+
onVisibleChange?: (visible: boolean) => void
|
|
20
|
+
format?: (labels: string[]) => string
|
|
21
|
+
extra?: string
|
|
22
|
+
triggerType?: string
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
children?: ReactNode
|
|
25
|
+
locale?: { okText?: string; dismissText?: string; extra?: string }
|
|
26
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Components
|
|
3
|
+
type: Data Entry
|
|
4
|
+
title: Picker
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Choose from a set of data, e.g. Country choice.
|
|
8
|
+
|
|
9
|
+
### Rules
|
|
10
|
+
- Try to use Picker to help users complete the input, to avoid the user through the keyboard directly input.
|
|
11
|
+
- DatePicker is Picker's specific pattern.
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### Props
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
type PickerColumnItem = {
|
|
19
|
+
label: string | ReactNode
|
|
20
|
+
value: string | number
|
|
21
|
+
key?: string | number
|
|
22
|
+
children?: PickerColumnItem[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type PickerColumn = PickerColumnItem[]
|
|
26
|
+
|
|
27
|
+
type PickerValue = string | number
|
|
28
|
+
|
|
29
|
+
type PickerValueExtend = {
|
|
30
|
+
columns: PickerColumn[]
|
|
31
|
+
items: (PickerColumnItem | undefined)[]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Properties | Descrition | Type | Default | Version
|
|
36
|
+
-----------|------------|------|--------|--------
|
|
37
|
+
| data | data source | `PickerColumn` / `PickerColumn[]` | - | |
|
|
38
|
+
| value | Selected options | `PickerValue[]` | - | |
|
|
39
|
+
| defaultValue | Default selected options | `PickerValue[]` | - | |
|
|
40
|
+
| cascade | whether cascade <br/>child cascade get from `data[].children` | Boolean | `true` | |
|
|
41
|
+
| cols | col numbers | Number | `3` | |
|
|
42
|
+
| onChange | selected callback function, can use [rc-form](https://github.com/react-component/form) | `(value: PickerValue[], extend: PickerValueExtend) => void` | - | |
|
|
43
|
+
| onPickerChange | trigger on each column of selected data is changed | `(value: PickerValue[], index: number) => void` | - | |
|
|
44
|
+
| onVisibleChange | visible state change callback | `(visible: bool): void` | - | |
|
|
45
|
+
| renderLabel | The function to custom rendering the label shown on a column | `(item: PickerColumnItem, index: number) => ReactNode` | `(item) => item.label` | |
|
|
46
|
+
| locale | international, can override the configuration of the global [LocaleProvider](/components/locale-provider) | Object: Object: {okText, dismissText, extra} | - | |
|
|
47
|
+
| title | title | ReactNode | - | |
|
|
48
|
+
| okText | ok text | String | `确定` | |
|
|
49
|
+
| dismissText | dismiss text | String | `取消` | |
|
|
50
|
+
| onOk | handler called when click ok | `(value: PickerValue[], extend: PickerValueExtend) => void` | - | |
|
|
51
|
+
| onDismiss | handler called when click cancel | (): void | - | |
|
|
52
|
+
| okButtonProps | The ok button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd' }` | `5.1.3` |
|
|
53
|
+
| dismissButtonProps | The dismiss button props | [TouchableHighlightProps](https://reactnative.dev/docs/touchablehighlight) | `{ activeOpacity:1, underlayColor:'#ddd' }` | `5.1.3` |
|
|
54
|
+
| visible | Whether to show or hide the Picker | Boolean | - | |
|
|
55
|
+
| loading | Should the Picker displays as loading state | Boolean | - | |
|
|
56
|
+
| loadingContent | The loading content displayed in loading state | ReactNode | - | |
|
|
57
|
+
| indicatorStyle | style of default Indicator | Object | - | |
|
|
58
|
+
|
|
59
|
+
### Custom Style
|
|
60
|
+
|
|
61
|
+
Properties | Descrition | Type | Default
|
|
62
|
+
-----------|------------|------|--------
|
|
63
|
+
| style | style | `StyleProp<ViewStyle>` | - |
|
|
64
|
+
| styles | inner component styles | same as [PickerViewStyle](/components//picker-view/#pickerviewstyle-interface) | - |
|
|
65
|
+
| itemStyle| style to apply to each of the item labels | `StyleProp<TextStyle>` | - |
|
|
66
|
+
| itemHeight | Height of option item, calculated by `numberOfLines` when without value; `itemStyle` was not allowed to set `{height}` | Number | - |
|
|
67
|
+
| numberOfLines | Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number | Number | `1` |
|
|
68
|
+
|
|
69
|
+
#### Mask View
|
|
70
|
+
|
|
71
|
+
Support custom mask style, such as using the gradient component `<LinearGradient />`. Default is white translucency.
|
|
72
|
+
|
|
73
|
+
Properties | Descrition | Type | Default
|
|
74
|
+
-----------|------------|------|--------
|
|
75
|
+
| renderMaskTop | The function to custom rendering the mask top half view | `()=> ReactNode` | `<View style={{ flex: 1, backgroundColor: 'rgba(255,255,255,0.8)' }} />` |
|
|
76
|
+
| renderMaskBottom | The function to custom rendering the mask bottom half view | `()=> ReactNode` | `<View style={{ flex: 1, backgroundColor: 'rgba(255,255,255,0.8)' }} />` |
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Custom Children
|
|
80
|
+
Picker's children is best to [List.Item](/components/list/#List.Item), if not, need to be a custom component (the `onPress`/`extra` props need to be handled in the component):
|
|
81
|
+
|
|
82
|
+
Properties | Descrition | Type | Default | Version |
|
|
83
|
+
-----------|------------|------|--------|--------
|
|
84
|
+
| children| usually `List.Item` | `ReactNode`/`({extra, value, toggle})=>ReactNode` | - | `5.2.0` add function as Children |
|
|
85
|
+
| extra | Picker's children `extra` prop, display when no `value` | String | `please select` | |
|
|
86
|
+
| format | a function that formats the selected value | (labels: string[]): any | `(labels) => { return labels.join(','); } ` | |
|
|
87
|
+
| triggerType | Press event name | String | `onPress` | |
|
|
88
|
+
| disabled | set disabled | Boolean | `false` | |
|
|
89
|
+
|
|
90
|
+
### PickerActions
|
|
91
|
+
Properties | Descrition | Type
|
|
92
|
+
-----------|------------|-----
|
|
93
|
+
| close | Close Picker | `() => void` |
|
|
94
|
+
| open | Open Picker | `() => void` |
|
|
95
|
+
| toggle | Toggle the visible state of Picker | `() => void` |
|
|
96
|
+
|
|
97
|
+
### Ref
|
|
98
|
+
Same as PickerActions
|