ipanel-rnapp-ajb-base 1.0.14 → 1.0.16
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 +5 -0
- package/app/components/common/PickerV1/index.js +93 -0
- package/app/components/common/PickerV2/index.js +137 -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 +225 -0
- package/app/components/common/PickerV2Base/picker/Popup.tsx +79 -0
- package/app/components/common/PickerV2Base/picker/PopupPickerTypes.tsx +17 -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 +63 -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/common/SheetManage/index.js +72 -0
- package/app/components/index.js +2 -0
- package/package.json +19 -19
package/app/App.js
CHANGED
|
@@ -19,6 +19,7 @@ import DeviceInfo from 'react-native-device-info';
|
|
|
19
19
|
import {SafeAreaProvider, SafeAreaView} from 'react-native-safe-area-context';
|
|
20
20
|
import VersionUpdateConfirm from './components/VersionUpdateConfirm';
|
|
21
21
|
// import NetInfo from '@react-native-community/netinfo';
|
|
22
|
+
import { Provider } from '@ant-design/react-native';
|
|
22
23
|
|
|
23
24
|
// 重要:base.js需放在一切自定义代码之前初始化
|
|
24
25
|
import './base.js';
|
|
@@ -34,6 +35,7 @@ import Loading from './components/common/Loading';
|
|
|
34
35
|
import Toast from './components/common/Toast';
|
|
35
36
|
import Dialog from './components/common/Dialog';
|
|
36
37
|
import Notify from './components/common/Notify';
|
|
38
|
+
import SheetManage from './components/common/SheetManage';
|
|
37
39
|
import storage from './storage';
|
|
38
40
|
|
|
39
41
|
import {navigationRef} from './utils/RootNavigation';
|
|
@@ -396,6 +398,7 @@ const App = () => {
|
|
|
396
398
|
const renderContent = () => {
|
|
397
399
|
return (
|
|
398
400
|
<>
|
|
401
|
+
<Provider>
|
|
399
402
|
<SheetProvider>
|
|
400
403
|
<NavigationContainer
|
|
401
404
|
ref={navigationRef}
|
|
@@ -437,6 +440,7 @@ const App = () => {
|
|
|
437
440
|
<Toast onRef={ref => (global.toast = ref)} />
|
|
438
441
|
<Notify onRef={ref => (global.notify = ref)} />
|
|
439
442
|
<Dialog onRef={ref => (global.dialog = ref)} />
|
|
443
|
+
<SheetManage onRef={ref => (global.sheetManager = ref)} />
|
|
440
444
|
{versionUpdateConfirmVisible && (
|
|
441
445
|
<VersionUpdateConfirm
|
|
442
446
|
onVisibleChange={setVersionUpdateConfirmVisible}
|
|
@@ -449,6 +453,7 @@ const App = () => {
|
|
|
449
453
|
<View style={styles.touchableContainer} />
|
|
450
454
|
</TouchableWithoutFeedback>
|
|
451
455
|
)}
|
|
456
|
+
</Provider>
|
|
452
457
|
</>
|
|
453
458
|
);
|
|
454
459
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React,{useState} from 'react';
|
|
2
|
+
import {View, Text, StyleSheet} from 'react-native';
|
|
3
|
+
import {Picker} from '@ant-design/react-native';
|
|
4
|
+
import px from '../../../utils/scaleSize';
|
|
5
|
+
const pickerStyles = {
|
|
6
|
+
okText: {color: '#E86003',borderLeftColor:'#F0F0F0',borderLeftWidth:1,width:px(500)},
|
|
7
|
+
dismissText: {color: '#666',width:px(500),},
|
|
8
|
+
container:{borderTopLeftRadius:px(20),borderTopRightRadius:px(20)},
|
|
9
|
+
wrappper:{borderTopLeftRadius:px(20),borderTopRightRadius:px(20)},
|
|
10
|
+
headerItem:{flex:0},
|
|
11
|
+
header:{
|
|
12
|
+
borderBottomWidth:px(0),
|
|
13
|
+
borderTopWidth:1,
|
|
14
|
+
borderTopColor:'#F0F0F0'
|
|
15
|
+
},
|
|
16
|
+
maskMiddle:{borderColor:'transparent'},
|
|
17
|
+
}
|
|
18
|
+
const pickerStyle = {height:px(700)}
|
|
19
|
+
|
|
20
|
+
const PickerV1 = ({
|
|
21
|
+
renderMaskTop=()=>{return <View></View>},
|
|
22
|
+
renderMaskBottom=()=>{return <View></View>},
|
|
23
|
+
styles={},
|
|
24
|
+
style={},
|
|
25
|
+
itemHeight=px(140),
|
|
26
|
+
visible=false,
|
|
27
|
+
pickerData = [],
|
|
28
|
+
dealPickerCommit=()=>{},
|
|
29
|
+
dealPickerCancel = () => {},
|
|
30
|
+
renderItem,
|
|
31
|
+
defaultValue = [],
|
|
32
|
+
pickedIndex=0,
|
|
33
|
+
changePickedIndex=()=>{}
|
|
34
|
+
}) => {
|
|
35
|
+
const handlePickerChange=(item)=>{
|
|
36
|
+
// console.log(item)
|
|
37
|
+
const index = pickerData.findIndex(item_=>{
|
|
38
|
+
return item[0] === item_.value
|
|
39
|
+
})
|
|
40
|
+
// console.log(index)
|
|
41
|
+
changePickedIndex(index)
|
|
42
|
+
}
|
|
43
|
+
const handlePikerCommit = (item) => {
|
|
44
|
+
dealPickerCommit(item)
|
|
45
|
+
}
|
|
46
|
+
const handlePickerCancel = () => {
|
|
47
|
+
dealPickerCancel()
|
|
48
|
+
}
|
|
49
|
+
const renderLabel = (item, index) => {
|
|
50
|
+
return (
|
|
51
|
+
<Text
|
|
52
|
+
key={index}
|
|
53
|
+
style={[styless.pickerItemCom,
|
|
54
|
+
index===pickedIndex?styless.pickedPicker:
|
|
55
|
+
{fontSize: px(50),color:Math.abs(index-pickedIndex)===1?'#999':'#eee'},
|
|
56
|
+
]}
|
|
57
|
+
>
|
|
58
|
+
{item.value}
|
|
59
|
+
</Text>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
return (
|
|
63
|
+
<View>
|
|
64
|
+
<Picker
|
|
65
|
+
data={pickerData}
|
|
66
|
+
visible={visible}
|
|
67
|
+
renderMaskTop={renderMaskTop}
|
|
68
|
+
renderMaskBottom={renderMaskBottom}
|
|
69
|
+
styles={{...pickerStyles,...styles}}
|
|
70
|
+
renderLabel={renderItem||renderLabel}
|
|
71
|
+
style={{...pickerStyle,...style}}
|
|
72
|
+
itemHeight={itemHeight}
|
|
73
|
+
defaultValue = {defaultValue}
|
|
74
|
+
onPickerChange={handlePickerChange}
|
|
75
|
+
onOk={handlePikerCommit}
|
|
76
|
+
onDismiss={handlePickerCancel}
|
|
77
|
+
onClose={handlePickerCancel}
|
|
78
|
+
>
|
|
79
|
+
</Picker>
|
|
80
|
+
</View>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
const styless = StyleSheet.create({
|
|
84
|
+
pickerItemCom:{
|
|
85
|
+
textAlign:'center',
|
|
86
|
+
},
|
|
87
|
+
pickedPicker:{
|
|
88
|
+
color: '#333',
|
|
89
|
+
fontSize:px(72),
|
|
90
|
+
fontWeight:'bold'
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
export default PickerV1;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React,{useEffect, useState} from 'react';
|
|
2
|
+
import {View, Text, StyleSheet} from 'react-native';
|
|
3
|
+
import Picker from '../PickerV2Base/picker';
|
|
4
|
+
import px from '../../../utils/scaleSize';
|
|
5
|
+
import {
|
|
6
|
+
useAnimatedStyle,
|
|
7
|
+
withSpring,
|
|
8
|
+
} from 'react-native-reanimated';
|
|
9
|
+
const pickerStyles = {
|
|
10
|
+
okView:{borderLeftColor:'#F0F0F0',borderLeftWidth:1},
|
|
11
|
+
okText: {color: '#E86003',width:px(500)},
|
|
12
|
+
dismissText: {color: '#666',width:px(500),},
|
|
13
|
+
container:{borderTopLeftRadius:px(20),borderTopRightRadius:px(20)},
|
|
14
|
+
wrappper:{borderTopLeftRadius:px(20),borderTopRightRadius:px(20)},
|
|
15
|
+
headerItem:{flex:0},
|
|
16
|
+
header:{
|
|
17
|
+
borderBottomWidth:px(0),
|
|
18
|
+
borderTopWidth:1,
|
|
19
|
+
borderTopColor:'#F0F0F0',
|
|
20
|
+
backgroundColor: '#fff'
|
|
21
|
+
},
|
|
22
|
+
maskMiddle:{borderColor:'transparent'},
|
|
23
|
+
titleBox:{
|
|
24
|
+
width:'100%',
|
|
25
|
+
height:px(205),
|
|
26
|
+
backgroundColor:'#fff',
|
|
27
|
+
top:px(15)
|
|
28
|
+
},
|
|
29
|
+
titleContent:{
|
|
30
|
+
width:'100%',height:px(190),borderBottomColor:'#f0f0f0',borderBottomWidth:1,
|
|
31
|
+
borderTopRightRadius:px(20),borderTopLeftRadius:px(20)
|
|
32
|
+
},
|
|
33
|
+
titleText:{
|
|
34
|
+
fontSize:px(48),color:'#333',textAlign:'center',lineHeight:px(190)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const pickerStyle = {height:px(700)}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const PickerV2 = ({
|
|
41
|
+
renderMaskTop=()=>{return <View></View>},
|
|
42
|
+
renderMaskBottom=()=>{return <View></View>},
|
|
43
|
+
styles={},
|
|
44
|
+
style={},
|
|
45
|
+
itemHeight=px(140),
|
|
46
|
+
visible=false,
|
|
47
|
+
pickerData = [],
|
|
48
|
+
dealPickerCommit=()=>{},
|
|
49
|
+
dealPickerCancel = () => {},
|
|
50
|
+
renderItem,
|
|
51
|
+
defaultValue = [],
|
|
52
|
+
pickedIndex=0,
|
|
53
|
+
changePickedIndex=()=>{},
|
|
54
|
+
animatedStartValue,
|
|
55
|
+
animationEffects = {},
|
|
56
|
+
title
|
|
57
|
+
}) => {
|
|
58
|
+
|
|
59
|
+
// console.log(title)
|
|
60
|
+
const customSpringStyles = useAnimatedStyle(() => {
|
|
61
|
+
return {
|
|
62
|
+
transform: [
|
|
63
|
+
{
|
|
64
|
+
translateY: withSpring(animatedStartValue, {...{
|
|
65
|
+
damping: 20,
|
|
66
|
+
stiffness: 100,
|
|
67
|
+
mass:0.5
|
|
68
|
+
},...animationEffects}),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// console.log(defaultValue)
|
|
75
|
+
const handlePickerChange=(item)=>{
|
|
76
|
+
// console.log(item)
|
|
77
|
+
const index = pickerData.findIndex(item_=>{
|
|
78
|
+
return item[0] === item_.value
|
|
79
|
+
})
|
|
80
|
+
// console.log(index)
|
|
81
|
+
changePickedIndex(index)
|
|
82
|
+
}
|
|
83
|
+
const handlePikerCommit = (item) => {
|
|
84
|
+
// console.log(item)
|
|
85
|
+
dealPickerCommit(item)
|
|
86
|
+
}
|
|
87
|
+
const handlePickerCancel = () => {
|
|
88
|
+
dealPickerCancel()
|
|
89
|
+
}
|
|
90
|
+
const renderLabel = (item, index) => {
|
|
91
|
+
// console.log(item)
|
|
92
|
+
return (
|
|
93
|
+
<Text
|
|
94
|
+
key={index}
|
|
95
|
+
style={[styless.pickerItemCom,
|
|
96
|
+
index===pickedIndex?styless.pickedPicker:
|
|
97
|
+
{fontSize: px(50),color:Math.abs(index-pickedIndex)===1?'#999':'#eee'},
|
|
98
|
+
]}
|
|
99
|
+
>
|
|
100
|
+
{item.label}
|
|
101
|
+
</Text>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
return (
|
|
105
|
+
<View>
|
|
106
|
+
<Picker
|
|
107
|
+
data={pickerData}
|
|
108
|
+
visible={visible}
|
|
109
|
+
title={title}
|
|
110
|
+
renderMaskTop={renderMaskTop}
|
|
111
|
+
renderMaskBottom={renderMaskBottom}
|
|
112
|
+
styles={{...pickerStyles,...styles}}
|
|
113
|
+
renderLabel={renderItem||renderLabel}
|
|
114
|
+
style={{...pickerStyle,...style}}
|
|
115
|
+
itemHeight={itemHeight}
|
|
116
|
+
defaultValue = {defaultValue}
|
|
117
|
+
onPickerChange={handlePickerChange}
|
|
118
|
+
onOk={handlePikerCommit}
|
|
119
|
+
onDismiss={handlePickerCancel}
|
|
120
|
+
onClose={handlePickerCancel}
|
|
121
|
+
customSpringStyles={typeof animatedStartValue !== 'undefined'?customSpringStyles:{}}
|
|
122
|
+
>
|
|
123
|
+
</Picker>
|
|
124
|
+
</View>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
const styless = StyleSheet.create({
|
|
128
|
+
pickerItemCom:{
|
|
129
|
+
textAlign:'center',
|
|
130
|
+
},
|
|
131
|
+
pickedPicker:{
|
|
132
|
+
color: '#333',
|
|
133
|
+
fontSize:px(72),
|
|
134
|
+
fontWeight:'bold'
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
export default PickerV2;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function getComponentLocale(
|
|
2
|
+
props: any,
|
|
3
|
+
context: any,
|
|
4
|
+
componentName: string,
|
|
5
|
+
getDefaultLocale: () => any,
|
|
6
|
+
) {
|
|
7
|
+
let locale: any = {}
|
|
8
|
+
if (context && context.antLocale && context.antLocale[componentName]) {
|
|
9
|
+
locale = context.antLocale[componentName]
|
|
10
|
+
} else {
|
|
11
|
+
const defaultLocale = getDefaultLocale()
|
|
12
|
+
// TODO: make default lang of antd be English
|
|
13
|
+
// https://github.com/ant-design/ant-design/issues/6334
|
|
14
|
+
locale = defaultLocale.default || defaultLocale
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let result = {
|
|
18
|
+
...locale,
|
|
19
|
+
}
|
|
20
|
+
if (props.locale) {
|
|
21
|
+
result = {
|
|
22
|
+
...result,
|
|
23
|
+
...props.locale,
|
|
24
|
+
}
|
|
25
|
+
if (props.locale.lang) {
|
|
26
|
+
result.lang = {
|
|
27
|
+
...locale.lang,
|
|
28
|
+
...props.locale.lang,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getLocaleCode(context: any) {
|
|
36
|
+
const localeCode = context.antLocale && context.antLocale.locale
|
|
37
|
+
// Had use LocaleProvide but didn't set locale
|
|
38
|
+
if (context.antLocale && context.antLocale.exist && !localeCode) {
|
|
39
|
+
return 'zh-cn'
|
|
40
|
+
}
|
|
41
|
+
return localeCode
|
|
42
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Animated, EasingFunction } from 'react-native'
|
|
3
|
+
|
|
4
|
+
type animateType = (_TimingAnimationConfig: {
|
|
5
|
+
toValue?:
|
|
6
|
+
| number
|
|
7
|
+
| Animated.AnimatedValue
|
|
8
|
+
| { x: number; y: number }
|
|
9
|
+
| Animated.AnimatedValueXY
|
|
10
|
+
| Animated.AnimatedInterpolation
|
|
11
|
+
easing?: EasingFunction
|
|
12
|
+
duration?: number
|
|
13
|
+
delay?: number
|
|
14
|
+
useNativeDriver?: boolean
|
|
15
|
+
}) => void
|
|
16
|
+
|
|
17
|
+
interface ConfigureInterface {
|
|
18
|
+
initialValue: number
|
|
19
|
+
animate: animateType
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Animated.Value hook
|
|
23
|
+
export function useAnimate(configure: ConfigureInterface) {
|
|
24
|
+
const useAnimatedValue = (initialValue: number) => {
|
|
25
|
+
const ref = React.useRef(new Animated.Value(initialValue))
|
|
26
|
+
return ref.current
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const animatedValue = useAnimatedValue(configure.initialValue)
|
|
30
|
+
|
|
31
|
+
return [animatedValue]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Animated.timing hook
|
|
35
|
+
export function useAnimatedTiming(): [Animated.Value, animateType] {
|
|
36
|
+
const animatedRef = React.useRef<Animated.CompositeAnimation | void>()
|
|
37
|
+
|
|
38
|
+
const animatedFunc = React.useCallback(
|
|
39
|
+
({ toValue = 1, duration = 200, easing, useNativeDriver = false }) => {
|
|
40
|
+
animatedRef.current?.stop()
|
|
41
|
+
animatedRef.current = Animated.timing(animatedValue, {
|
|
42
|
+
toValue,
|
|
43
|
+
duration,
|
|
44
|
+
easing,
|
|
45
|
+
useNativeDriver,
|
|
46
|
+
}).start()
|
|
47
|
+
},
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
[animatedValue],
|
|
50
|
+
)
|
|
51
|
+
var [animatedValue] = useAnimate({
|
|
52
|
+
initialValue: 0,
|
|
53
|
+
animate: animatedFunc,
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return [animatedValue, animatedFunc]
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
DeviceEventEmitter,
|
|
4
|
+
EmitterSubscription,
|
|
5
|
+
GestureResponderEvent,
|
|
6
|
+
NativeEventEmitter,
|
|
7
|
+
} from 'react-native'
|
|
8
|
+
|
|
9
|
+
export const USE_CLICK_AWAY_EVENT_NAME = 'ANT_DESIGN_MOBILE_RN_USE_CLICK_AWAY'
|
|
10
|
+
|
|
11
|
+
export default function useClickAway(
|
|
12
|
+
onClickAway: (event: GestureResponderEvent) => void,
|
|
13
|
+
) {
|
|
14
|
+
const TopViewEventEmitter = useMemo(
|
|
15
|
+
() => DeviceEventEmitter || new NativeEventEmitter(),
|
|
16
|
+
[],
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
const onClickAwayRef = useRef<EmitterSubscription>()
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onClickAwayRef.current = TopViewEventEmitter.addListener(
|
|
23
|
+
USE_CLICK_AWAY_EVENT_NAME,
|
|
24
|
+
onClickAway,
|
|
25
|
+
)
|
|
26
|
+
return () => {
|
|
27
|
+
onClickAwayRef.current?.remove?.()
|
|
28
|
+
}
|
|
29
|
+
}, [TopViewEventEmitter, onClickAway])
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
type AnyObject = Record<PropertyKey, any>
|
|
4
|
+
|
|
5
|
+
export function isFragment(child: any): boolean {
|
|
6
|
+
return child && React.isValidElement(child) && child.type === React.Fragment
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type RenderProps = AnyObject | ((originProps: AnyObject) => AnyObject | void)
|
|
10
|
+
|
|
11
|
+
export const replaceElement = <P>(
|
|
12
|
+
element: React.ReactNode,
|
|
13
|
+
replacement: React.ReactNode,
|
|
14
|
+
props?: RenderProps,
|
|
15
|
+
) => {
|
|
16
|
+
if (!React.isValidElement<P>(element)) {
|
|
17
|
+
return replacement
|
|
18
|
+
}
|
|
19
|
+
return React.cloneElement<P>(
|
|
20
|
+
element,
|
|
21
|
+
typeof props === 'function' ? props(element.props || {}) : props,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function cloneElement<P>(element: React.ReactNode, props?: RenderProps) {
|
|
26
|
+
return replaceElement<P>(element, element, props) as React.ReactElement
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const assignWith = require('lodash.assignwith')
|
|
2
|
+
|
|
3
|
+
export function mergeProps<A, B>(a: A, b: B): B & A
|
|
4
|
+
export function mergeProps<A, B, C>(a: A, b: B, c: C): C & B & A
|
|
5
|
+
export function mergeProps(...items: any[]) {
|
|
6
|
+
function customizer(objValue: any, srcValue: any) {
|
|
7
|
+
return srcValue === undefined ? objValue : srcValue
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let ret = { ...items[0] }
|
|
11
|
+
for (let i = 1; i < items.length; i++) {
|
|
12
|
+
ret = assignWith(ret, items[i], customizer)
|
|
13
|
+
}
|
|
14
|
+
return ret
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
export type DisabledType = boolean | undefined
|
|
4
|
+
|
|
5
|
+
const DisabledContext = React.createContext<DisabledType>(false)
|
|
6
|
+
|
|
7
|
+
export interface DisabledContextProps {
|
|
8
|
+
disabled?: DisabledType
|
|
9
|
+
children?: React.ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const DisabledContextProvider: React.FC<DisabledContextProps> = ({
|
|
13
|
+
children,
|
|
14
|
+
disabled,
|
|
15
|
+
}) => {
|
|
16
|
+
const originDisabled = React.useContext(DisabledContext)
|
|
17
|
+
return (
|
|
18
|
+
<DisabledContext.Provider value={disabled ?? originDisabled}>
|
|
19
|
+
{children}
|
|
20
|
+
</DisabledContext.Provider>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default DisabledContext
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import DatePickerView from '../date-picker-view/locale/en_US'
|
|
2
|
+
import DatePicker from '../date-picker/locale/en_US'
|
|
3
|
+
import Form from '../form/locale/en_US'
|
|
4
|
+
import InputItem from '../input-item/locale/en_US'
|
|
5
|
+
import ListView from '../list-view/locale/en_US'
|
|
6
|
+
import Modal from '../modal/locale/en_US'
|
|
7
|
+
import Pagination from '../pagination/locale/en_US'
|
|
8
|
+
import Picker from '../picker/locale/en_US'
|
|
9
|
+
import SearchBar from '../search-bar/locale/en_US'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'en',
|
|
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/es_ES'
|
|
2
|
+
import DatePicker from '../date-picker/locale/es_ES'
|
|
3
|
+
import Form from '../form/locale/es_ES'
|
|
4
|
+
import InputItem from '../input-item/locale/es_ES'
|
|
5
|
+
import ListView from '../list-view/locale/es_ES'
|
|
6
|
+
import Modal from '../modal/locale/es_ES'
|
|
7
|
+
import Pagination from '../pagination/locale/es_ES'
|
|
8
|
+
import Picker from '../picker/locale/es_ES'
|
|
9
|
+
import SearchBar from '../search-bar/locale/es_ES'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'es',
|
|
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/fa_IR'
|
|
2
|
+
import DatePicker from '../date-picker/locale/fa_IR'
|
|
3
|
+
import Form from '../form/locale/fa_IR'
|
|
4
|
+
import InputItem from '../input-item/locale/fa_IR'
|
|
5
|
+
import ListView from '../list-view/locale/fa_IR'
|
|
6
|
+
import Modal from '../modal/locale/fa_IR'
|
|
7
|
+
import Pagination from '../pagination/locale/fa_IR'
|
|
8
|
+
import Picker from '../picker/locale/fa_IR'
|
|
9
|
+
import SearchBar from '../search-bar/locale/fa_IR'
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
locale: 'fa',
|
|
13
|
+
DatePicker,
|
|
14
|
+
DatePickerView,
|
|
15
|
+
InputItem,
|
|
16
|
+
Modal,
|
|
17
|
+
Pagination,
|
|
18
|
+
Picker,
|
|
19
|
+
SearchBar,
|
|
20
|
+
ListView,
|
|
21
|
+
Form,
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Components
|
|
3
|
+
title: Provider
|
|
4
|
+
type: Other
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`Provider` provides a uniform localization support for built-in text of components.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
`Provider` takes use of [context](https://facebook.github.io/react/docs/context.html), a feature of React, to accomplish global effectiveness by wrapping the app only once.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
```jsx
|
|
15
|
+
import enUS from '@ant-design/react-native/lib/locale-provider/en_US';
|
|
16
|
+
|
|
17
|
+
...
|
|
18
|
+
|
|
19
|
+
return <Provider locale={enUS}><App /></Provider>;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
We support English and Chinese temporarily, all locale packages can be found in [here](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider/).
|
|
23
|
+
|
|
24
|
+
### Add a new language
|
|
25
|
+
|
|
26
|
+
If you can't find your language, you are welcome to create a locale package based on [en_US]((https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/locale-provider/en_US.tsx)) and send us a pull request.
|
|
27
|
+
|
|
28
|
+
### Other localization needs
|
|
29
|
+
|
|
30
|
+
This component aims for localization of the built-in text, if you want to support other documents, we recommend using [react-intl](https://github.com/yahoo/react-intl), refer to [Intl demo 1](http://github.com/ant-design/intl-example) and [Intl demo 2](http://yiminghe.me/learning-react/examples/react-intl.html?locale=en-US).
|
|
31
|
+
|
|
32
|
+
## API
|
|
33
|
+
|
|
34
|
+
| Property | Description | Type | Default |
|
|
35
|
+
| -------- | ------------------------------------------------------------------------------------------------------------------------------- | ------ | ------- |
|
|
36
|
+
| locale | anguage package setting, you can find the packages in this path: `@ant-design/react-native/lib/locale-provider/` | object | - |
|
|
37
|
+
| theme | Theme customization [theme](https://github.com/ant-design/ant-design-mobile-rn/blob/master/components/style/themes/default.tsx) | object | - |
|