ordering-ui-react-native 0.15.7 → 0.15.8
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useLanguage, useOrder } from 'ordering-components/native';
|
|
3
3
|
import { useTheme } from 'styled-components/native';
|
|
4
|
-
import { StyleSheet, View, Dimensions } from 'react-native';
|
|
4
|
+
import { StyleSheet, View, Dimensions, Platform, useWindowDimensions } from 'react-native';
|
|
5
5
|
import { OButton, OIcon, OText } from '../shared';
|
|
6
6
|
import { LogoWrapper, Slogan } from './styles';
|
|
7
7
|
import { LanguageSelector } from '../LanguageSelector'
|
|
@@ -11,6 +11,7 @@ import { _setStoreData } from '../../providers/StoreUtil';
|
|
|
11
11
|
const windowHeight = Dimensions.get('window').height
|
|
12
12
|
|
|
13
13
|
export const Home = (props: any) => {
|
|
14
|
+
const { width, height } = useWindowDimensions();
|
|
14
15
|
const { onNavigationRedirect } = props;
|
|
15
16
|
|
|
16
17
|
const theme = useTheme();
|
|
@@ -25,7 +26,7 @@ export const Home = (props: any) => {
|
|
|
25
26
|
return (
|
|
26
27
|
<View style={styles.container}>
|
|
27
28
|
<View style={styles.wrapperContent}>
|
|
28
|
-
<View style={
|
|
29
|
+
<View style={{ paddingTop: (height <= 756 && Platform.OS !== 'ios') ? (height * 0.05) : 0, marginLeft: 10 }}>
|
|
29
30
|
<LanguageSelector />
|
|
30
31
|
</View>
|
|
31
32
|
<LogoWrapper>
|
|
@@ -74,9 +75,6 @@ export const Home = (props: any) => {
|
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
const styles = StyleSheet.create({
|
|
77
|
-
languageSelector: {
|
|
78
|
-
marginRight: 10
|
|
79
|
-
},
|
|
80
78
|
textLink: {
|
|
81
79
|
flexDirection: 'row',
|
|
82
80
|
textAlign: 'center',
|
|
@@ -1,140 +1,108 @@
|
|
|
1
|
-
import React, { useState
|
|
2
|
-
import {
|
|
3
|
-
import { useTheme } from 'styled-components/native'
|
|
4
|
-
import {
|
|
5
|
-
LanguageSelector as LanguageSelectorController,
|
|
6
|
-
useLanguage
|
|
7
|
-
} from 'ordering-components/native'
|
|
8
|
-
import { StyleSheet } from 'react-native'
|
|
9
|
-
import RNRestart from 'react-native-restart'
|
|
10
|
-
import Picker from 'react-native-country-picker-modal';
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { LanguageSelector as LanguageSelectorController, useOrder } from 'ordering-components/native'
|
|
3
|
+
import { useTheme } from 'styled-components/native';
|
|
4
|
+
import { I18nManager, Platform, StyleSheet, View } from 'react-native'
|
|
11
5
|
|
|
12
|
-
import
|
|
6
|
+
import RNPickerSelect from 'react-native-picker-select'
|
|
7
|
+
import { Container, DummyContainer } from './styles'
|
|
13
8
|
import { LanguageSelectorParams } from '../../types'
|
|
14
|
-
import {
|
|
9
|
+
import { OIcon } from '../shared'
|
|
10
|
+
import RNRestart from 'react-native-restart'
|
|
15
11
|
|
|
16
12
|
const LanguageSelectorUI = (props: LanguageSelectorParams) => {
|
|
13
|
+
|
|
17
14
|
const {
|
|
18
15
|
languagesState,
|
|
19
16
|
currentLanguage,
|
|
20
17
|
handleChangeLanguage,
|
|
21
|
-
|
|
18
|
+
pickerStyle
|
|
22
19
|
} = props
|
|
23
20
|
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
27
|
-
const [optionSelected, setOptionSelected] = useState<any>(null)
|
|
28
|
-
let current;
|
|
21
|
+
const [orderState] = useOrder()
|
|
22
|
+
const theme = useTheme();
|
|
29
23
|
|
|
30
|
-
const
|
|
31
|
-
|
|
24
|
+
const [language, setLanguage] = useState(currentLanguage)
|
|
25
|
+
|
|
26
|
+
const _pickerStyle = StyleSheet.create({
|
|
27
|
+
inputAndroid: {
|
|
28
|
+
color: '#000',
|
|
29
|
+
borderWidth: 1,
|
|
30
|
+
borderColor: theme.colors.clear,
|
|
31
|
+
padding: 10,
|
|
32
|
+
height: 40,
|
|
32
33
|
backgroundColor: theme.colors.disabled,
|
|
34
|
+
borderRadius: 8
|
|
33
35
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
inputIOS: {
|
|
37
|
+
color: '#000',
|
|
38
|
+
padding: 10,
|
|
36
39
|
height: 40,
|
|
40
|
+
borderWidth: 1,
|
|
41
|
+
marginStart: 20,
|
|
42
|
+
borderColor: theme.colors.clear,
|
|
43
|
+
backgroundColor: theme.colors.clear,
|
|
44
|
+
},
|
|
45
|
+
icon: {
|
|
46
|
+
width: 10,
|
|
47
|
+
marginTop: 9,
|
|
48
|
+
marginEnd: 10
|
|
49
|
+
},
|
|
50
|
+
placeholder: {
|
|
51
|
+
color: theme.colors.secundaryContrast
|
|
52
|
+
},
|
|
53
|
+
chevronDown: {
|
|
54
|
+
display: 'none'
|
|
55
|
+
},
|
|
56
|
+
chevronUp: {
|
|
57
|
+
display: 'none'
|
|
37
58
|
}
|
|
38
59
|
})
|
|
39
60
|
|
|
40
61
|
const _languages = languagesState?.languages?.map((language: any) => {
|
|
41
62
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
63
|
+
value: language?.code,
|
|
64
|
+
label: language?.name,
|
|
65
|
+
inputLabel: language?.name
|
|
45
66
|
}
|
|
46
67
|
})
|
|
47
68
|
_languages && _languages.sort((a: any, b: any) =>
|
|
48
|
-
(a.
|
|
69
|
+
(a.content > b.content) ? 1 : ((b.content > a.content) ? -1 : 0)
|
|
49
70
|
)
|
|
50
71
|
|
|
51
|
-
const langSelectedObj: any = _languages && _languages.find((item: any) => item.value === currentLanguage) || {}
|
|
52
|
-
|
|
53
72
|
const changeDirection = async (language: any) => {
|
|
54
|
-
if(language !== 'ar'){
|
|
55
|
-
if (I18nManager.isRTL){
|
|
73
|
+
if (language !== 'ar') {
|
|
74
|
+
if (I18nManager.isRTL) {
|
|
56
75
|
await I18nManager.forceRTL(false)
|
|
57
76
|
RNRestart.Restart();
|
|
58
77
|
}
|
|
59
78
|
} else {
|
|
60
|
-
if(!I18nManager.isRTL){
|
|
79
|
+
if (!I18nManager.isRTL) {
|
|
61
80
|
await I18nManager.forceRTL(true)
|
|
62
81
|
RNRestart.Restart();
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
|
|
67
|
-
const handlerChangeLanguage = (langCode
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
handleChangeLanguage(langCode)
|
|
86
|
+
const handlerChangeLanguage = (langCode?: any) => {
|
|
87
|
+
changeDirection(Platform.OS === 'ios' ? language : langCode)
|
|
88
|
+
handleChangeLanguage(Platform.OS === 'ios' ? language : langCode)
|
|
71
89
|
}
|
|
72
90
|
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (optionSelected === languageState?.language?.code && !languageState.loading) {
|
|
75
|
-
setIsOpen(false)
|
|
76
|
-
}
|
|
77
|
-
}, [languageState])
|
|
78
|
-
|
|
79
91
|
return (
|
|
80
92
|
<Container>
|
|
81
|
-
{languagesState?.languages
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}}
|
|
93
|
-
closeButtonImageStyle={Platform.OS === 'ios' && styles.closeBtn}
|
|
94
|
-
renderFlagButton={() => (
|
|
95
|
-
<>
|
|
96
|
-
<TouchableOpacity
|
|
97
|
-
onPress={() => setIsOpen(true)}
|
|
98
|
-
disabled={_languages.length === 0 || languageState.loading}
|
|
99
|
-
>
|
|
100
|
-
<SelectItemBtn isFromProfile={isFromProfile}>
|
|
101
|
-
<OText
|
|
102
|
-
color={theme.colors.secundaryContrast}
|
|
103
|
-
size={14}
|
|
104
|
-
>
|
|
105
|
-
{langSelectedObj.key.toUpperCase()}
|
|
106
|
-
</OText>
|
|
107
|
-
</SelectItemBtn>
|
|
108
|
-
</TouchableOpacity>
|
|
109
|
-
</>
|
|
110
|
-
)}
|
|
111
|
-
flatListProps={{
|
|
112
|
-
keyExtractor: (item: any) => item.value,
|
|
113
|
-
data: _languages || [],
|
|
114
|
-
renderItem: ({ item }: any) => (
|
|
115
|
-
<TouchableOpacity
|
|
116
|
-
style={langSelectedObj.value === item.value && styles.itemSelected}
|
|
117
|
-
disabled={langSelectedObj.value === item.value || languageState.loading}
|
|
118
|
-
onPress={() => handlerChangeLanguage(item.value)}
|
|
119
|
-
>
|
|
120
|
-
<SelectItem>
|
|
121
|
-
<View style={{ width: 40 }}>
|
|
122
|
-
{optionSelected === item.value && languageState.loading && (
|
|
123
|
-
<ActivityIndicator size="small" color={theme.colors.primary} />
|
|
124
|
-
)}
|
|
125
|
-
</View>
|
|
126
|
-
<OText
|
|
127
|
-
size={14}
|
|
128
|
-
style={{ marginRight: 10 }}
|
|
129
|
-
>
|
|
130
|
-
{item.label}
|
|
131
|
-
</OText>
|
|
132
|
-
</SelectItem>
|
|
133
|
-
</TouchableOpacity>
|
|
134
|
-
),
|
|
135
|
-
}}
|
|
93
|
+
{languagesState?.languages ? (
|
|
94
|
+
<RNPickerSelect
|
|
95
|
+
onValueChange={(val) => Platform.OS === 'ios' ? setLanguage(val) : handlerChangeLanguage(val)}
|
|
96
|
+
items={_languages || []}
|
|
97
|
+
value={Platform.OS === 'ios' ? language : currentLanguage}
|
|
98
|
+
style={pickerStyle ? pickerStyle : _pickerStyle}
|
|
99
|
+
useNativeAndroidPickerStyle={false}
|
|
100
|
+
placeholder={{}}
|
|
101
|
+
disabled={orderState.loading}
|
|
102
|
+
onClose={() => Platform.OS === 'ios' ? handlerChangeLanguage() : {}}
|
|
103
|
+
onDonePress={() => handlerChangeLanguage()}
|
|
136
104
|
/>
|
|
137
|
-
)}
|
|
105
|
+
) : <DummyContainer />}
|
|
138
106
|
</Container>
|
|
139
107
|
)
|
|
140
108
|
}
|
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
import styled from 'styled-components/native'
|
|
2
2
|
|
|
3
3
|
export const Container = styled.View`
|
|
4
|
-
align-items: flex-end;
|
|
5
|
-
justify-content: flex-end;
|
|
6
|
-
flex-direction: row;
|
|
7
|
-
`
|
|
8
|
-
|
|
9
|
-
export const SelectItem = styled.View`
|
|
10
|
-
padding: 8px;
|
|
11
4
|
align-items: center;
|
|
5
|
+
justify-content: flex-start;
|
|
12
6
|
flex-direction: row;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
border-width: 1px;
|
|
17
|
-
border-color: transparent;
|
|
18
|
-
border-radius: 10px;
|
|
19
|
-
max-width: 140px;
|
|
20
|
-
margin-vertical: 5px;
|
|
21
|
-
padding: 15px 20px;
|
|
22
|
-
background-color: ${(props: any) => props.isFromProfile ? 'transparent' : props.theme.colors.inputDisabled};
|
|
7
|
+
`
|
|
8
|
+
export const DummyContainer = styled.View`
|
|
9
|
+
height: 40px;
|
|
23
10
|
`
|
|
@@ -47,6 +47,40 @@ export const UserProfileForm = (props: ProfileParams) => {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
const _pickerStyle = StyleSheet.create({
|
|
51
|
+
inputAndroid: {
|
|
52
|
+
color: '#000',
|
|
53
|
+
borderWidth: 1,
|
|
54
|
+
borderColor: theme.colors.clear,
|
|
55
|
+
padding: 10,
|
|
56
|
+
height: 40,
|
|
57
|
+
backgroundColor: theme.colors.disabled,
|
|
58
|
+
borderRadius: 8
|
|
59
|
+
},
|
|
60
|
+
inputIOS: {
|
|
61
|
+
color: '#000',
|
|
62
|
+
padding: 10,
|
|
63
|
+
height: 40,
|
|
64
|
+
borderWidth: 1,
|
|
65
|
+
borderColor: theme.colors.clear,
|
|
66
|
+
backgroundColor: theme.colors.clear,
|
|
67
|
+
},
|
|
68
|
+
icon: {
|
|
69
|
+
width: 10,
|
|
70
|
+
marginTop: 9,
|
|
71
|
+
marginEnd: 10
|
|
72
|
+
},
|
|
73
|
+
placeholder: {
|
|
74
|
+
color: theme.colors.secundaryContrast
|
|
75
|
+
},
|
|
76
|
+
chevronDown: {
|
|
77
|
+
display: 'none'
|
|
78
|
+
},
|
|
79
|
+
chevronUp: {
|
|
80
|
+
display: 'none'
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
50
84
|
const onRedirect = (route: string, params?: any) => {
|
|
51
85
|
navigation.navigate(route, params)
|
|
52
86
|
}
|
|
@@ -97,7 +131,7 @@ export const UserProfileForm = (props: ProfileParams) => {
|
|
|
97
131
|
<View>
|
|
98
132
|
<LanguageContainer>
|
|
99
133
|
<Ionicons name='globe-outline' style={styles.iconStyle} />
|
|
100
|
-
<LanguageSelector
|
|
134
|
+
<LanguageSelector pickerStyle={_pickerStyle} />
|
|
101
135
|
</LanguageContainer>
|
|
102
136
|
<LogoutButton />
|
|
103
137
|
</View>
|
package/src/types/index.tsx
CHANGED