ikualo-ui-kit-mobile 0.2.2 → 0.2.4
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1309.2409.26012.0
|
|
@@ -10,6 +10,9 @@ export const stylesSelect = StyleSheet.create({
|
|
|
10
10
|
'select-container-disabled': {
|
|
11
11
|
backgroundColor: theme.colors.disabled,
|
|
12
12
|
},
|
|
13
|
+
'select-placeholder-readonly': {
|
|
14
|
+
color: theme.colors.grayText,
|
|
15
|
+
},
|
|
13
16
|
'select-content': {
|
|
14
17
|
borderBottomWidth: 1,
|
|
15
18
|
borderBottomColor: theme.colors.primary,
|
|
@@ -32,4 +35,4 @@ export const stylesSelect = StyleSheet.create({
|
|
|
32
35
|
borderBlockColor: theme.colors.lightPrimary,
|
|
33
36
|
padding: 16,
|
|
34
37
|
},
|
|
35
|
-
});
|
|
38
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { TouchableNativeFeedback, View, Image } from 'react-native';
|
|
1
|
+
import { TouchableNativeFeedback, View, Image, Touchable } from 'react-native';
|
|
2
2
|
import { Text } from 'react-native-paper';
|
|
3
3
|
import { ReactElement, useState } from 'react';
|
|
4
4
|
import { icons } from '../../../assets/icons/_icons';
|
|
5
5
|
import { SelectList } from '../../';
|
|
6
6
|
import { stylesSelect } from '../../../assets/styles/elements/select';
|
|
7
|
+
import SimpleLineIcons from '@expo/vector-icons/SimpleLineIcons';
|
|
8
|
+
import { TouchableWithoutFeedback } from 'react-native-gesture-handler';
|
|
7
9
|
|
|
8
10
|
interface IFSelect {
|
|
9
11
|
label: string;
|
|
@@ -12,31 +14,39 @@ interface IFSelect {
|
|
|
12
14
|
options: { value: string; label: ReactElement }[];
|
|
13
15
|
onSelect: (value: string) => void;
|
|
14
16
|
value?: string;
|
|
15
|
-
showInLabel?: "placeholder" | "label"
|
|
17
|
+
showInLabel?: "placeholder" | "label",
|
|
18
|
+
isReadOnly?: boolean;
|
|
16
19
|
}
|
|
17
20
|
export const Select = (props: IFSelect) => {
|
|
18
|
-
const { placeholder, options, onSelect, label, isDisabled, value, showInLabel } = props;
|
|
21
|
+
const { placeholder, options, onSelect, label, isDisabled, value, showInLabel, isReadOnly } = props;
|
|
19
22
|
const [showList, setShowList] = useState(false);
|
|
20
23
|
const [selected, setSelected] = useState<ReactElement | null>(
|
|
21
24
|
options?.find((option) => option.value === value)?.label ?? null
|
|
22
25
|
);
|
|
23
26
|
return (
|
|
24
27
|
<>
|
|
25
|
-
<
|
|
28
|
+
<TouchableWithoutFeedback
|
|
26
29
|
onPress={() => {
|
|
27
|
-
!isDisabled && setShowList(true);
|
|
30
|
+
(!isDisabled && !isReadOnly) && setShowList(true);
|
|
28
31
|
}}
|
|
29
32
|
>
|
|
30
33
|
<View
|
|
31
|
-
style={[
|
|
34
|
+
style={[
|
|
35
|
+
stylesSelect['select-container'],
|
|
36
|
+
isDisabled && stylesSelect['select-container-disabled'],
|
|
37
|
+
]}
|
|
32
38
|
>
|
|
33
39
|
<Text style={stylesSelect['select-label']}>{selected && label}</Text>
|
|
34
|
-
<View style={stylesSelect['select-content']
|
|
35
|
-
|
|
36
|
-
<
|
|
40
|
+
<View style={[stylesSelect['select-content'],
|
|
41
|
+
]}>
|
|
42
|
+
<Text style={[
|
|
43
|
+
stylesSelect['select-placeholder'],
|
|
44
|
+
isReadOnly && stylesSelect['select-placeholder-readonly'],
|
|
45
|
+
]}>{selected ?? placeholder}</Text>
|
|
46
|
+
{!isReadOnly && <SimpleLineIcons name={showList ? "arrow-up" : "arrow-down"} size={10} color="black" />}
|
|
37
47
|
</View>
|
|
38
48
|
</View>
|
|
39
|
-
</
|
|
49
|
+
</TouchableWithoutFeedback>
|
|
40
50
|
<SelectList
|
|
41
51
|
children={options}
|
|
42
52
|
label={showInLabel === "label" ? label : placeholder}
|
|
@@ -25,7 +25,7 @@ export const SelectList = (props: IFSelectList) => {
|
|
|
25
25
|
>
|
|
26
26
|
<TouchableWithoutFeedback>
|
|
27
27
|
<View style={stylesDialog.modalBackground}>
|
|
28
|
-
<View style={[stylesDialog['dialog-down'], stylesDialog['dialog-bottom']]}>
|
|
28
|
+
<View style={[stylesDialog['dialog-down'], stylesDialog['dialog-bottom'], { maxHeight: '90%' }]}>
|
|
29
29
|
|
|
30
30
|
<TouchableHighlight onPress={onDismiss} underlayColor={theme.colors.lightPrimary} style={stylesDialog['dialog-down-select-close']}>
|
|
31
31
|
<Icon
|
|
@@ -35,7 +35,7 @@ export const SelectList = (props: IFSelectList) => {
|
|
|
35
35
|
/>
|
|
36
36
|
</TouchableHighlight>
|
|
37
37
|
<Text style={[stylesDialog['dialog-select-title']]}>{label}</Text>
|
|
38
|
-
<ScrollView
|
|
38
|
+
<ScrollView>
|
|
39
39
|
{children?.map((child, index) => {
|
|
40
40
|
return (
|
|
41
41
|
<TouchableNativeFeedback
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { StyleProp, TextStyle, View } from 'react-native';
|
|
2
|
+
import { AppState, StyleProp, TextStyle, View } from 'react-native';
|
|
3
3
|
import { Text } from 'react-native-paper';
|
|
4
4
|
interface IFTimer {
|
|
5
5
|
onFinished?: () => void;
|
|
@@ -10,38 +10,92 @@ interface IFTimer {
|
|
|
10
10
|
export const Timer = (props: IFTimer) => {
|
|
11
11
|
const { onFinished, style, minutes, resetTimer } = props;
|
|
12
12
|
const [minutesTemp, setMinutesTemp] = useState<number>(minutes);
|
|
13
|
-
const [seconds, setSeconds] = useState<number>(
|
|
13
|
+
const [seconds, setSeconds] = useState<number>(0);
|
|
14
|
+
const [appState, setAppState] = useState(AppState.currentState);
|
|
15
|
+
const [lastTimestamp, setLastTimestamp] = useState(Date.now());
|
|
16
|
+
const [updateTime, setUpdateTime] = useState(false);
|
|
14
17
|
|
|
15
18
|
useEffect(() => {
|
|
16
|
-
let secondsInterval: number =
|
|
17
|
-
let minutesInterval: number = minutes;
|
|
19
|
+
let secondsInterval: number = updateTime ? seconds : 0;
|
|
20
|
+
let minutesInterval: number = updateTime ? minutesTemp : minutes;
|
|
21
|
+
setUpdateTime(false);
|
|
22
|
+
|
|
18
23
|
const intervalId = setInterval(() => {
|
|
19
|
-
if (
|
|
24
|
+
if (minutesInterval > 0 && secondsInterval === 0) {
|
|
25
|
+
secondsInterval = 59;
|
|
26
|
+
minutesInterval = minutesInterval - 1;
|
|
27
|
+
setMinutesTemp(minutesInterval);
|
|
28
|
+
setSeconds(secondsInterval);
|
|
29
|
+
} else if (secondsInterval > 0) {
|
|
20
30
|
secondsInterval = secondsInterval - 1;
|
|
21
31
|
setSeconds(secondsInterval);
|
|
22
|
-
} else {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
} else if (minutesInterval === 0 && secondsInterval === 0) {
|
|
33
|
+
clearInterval(intervalId);
|
|
34
|
+
onFinished && onFinished();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}, 1000);
|
|
38
|
+
|
|
39
|
+
const subscription = AppState.addEventListener("change", nextAppState => {
|
|
40
|
+
if (appState === "active" && nextAppState.match(/inactive|background/)) {
|
|
41
|
+
setLastTimestamp(Date.now());
|
|
42
|
+
} else if (appState.match(/inactive|background/) && nextAppState === "active") {
|
|
43
|
+
setUpdateTime(true);
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
const timeElapsed = Math.floor((now - lastTimestamp) / 1000);
|
|
46
|
+
let minElapsed = Math.floor(timeElapsed / 60)
|
|
47
|
+
let secElapsed = timeElapsed > 60 ? timeElapsed % 60 : timeElapsed
|
|
48
|
+
let secAux = 0
|
|
49
|
+
let newMin = 0
|
|
50
|
+
let newSec = 0
|
|
51
|
+
|
|
52
|
+
if (minElapsed > minutesTemp || (minElapsed === minutesTemp && secElapsed > seconds)) {
|
|
53
|
+
setSeconds(0);
|
|
54
|
+
setMinutesTemp(0);
|
|
27
55
|
clearInterval(intervalId);
|
|
28
56
|
onFinished && onFinished();
|
|
29
|
-
|
|
57
|
+
} else if (minElapsed > 0 && secElapsed > seconds) {
|
|
58
|
+
secAux = seconds - secElapsed
|
|
59
|
+
newSec = secAux < 0 ? 60 - (secAux * -1) : secAux
|
|
60
|
+
newMin = (minutesTemp - minElapsed) - (secAux < 0 ? 1 : 0)
|
|
61
|
+
setSeconds(newSec);
|
|
62
|
+
setMinutesTemp(newMin);
|
|
63
|
+
} else if (minElapsed > 0 && secElapsed > 0) {
|
|
64
|
+
newSec = seconds - secElapsed
|
|
65
|
+
newMin = minutesTemp - minElapsed
|
|
66
|
+
setSeconds(newSec);
|
|
67
|
+
setMinutesTemp(newMin);
|
|
68
|
+
} else if (minElapsed > 0 && secElapsed === 0) {
|
|
69
|
+
newMin = minutesTemp - minElapsed
|
|
70
|
+
setMinutesTemp(newMin);
|
|
71
|
+
} else if (secElapsed > seconds) {
|
|
72
|
+
secAux = seconds - secElapsed
|
|
73
|
+
newSec = secAux < 0 ? 60 - (secAux * -1) : secAux
|
|
74
|
+
newMin = minutesTemp - (secAux < 0 ? 1 : 0)
|
|
75
|
+
setSeconds(newSec);
|
|
76
|
+
setMinutesTemp(newMin);
|
|
77
|
+
} else if (secElapsed > 0) {
|
|
78
|
+
newSec = seconds - secElapsed
|
|
79
|
+
setSeconds(newSec);
|
|
30
80
|
}
|
|
31
81
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
82
|
+
setAppState(nextAppState);
|
|
83
|
+
return
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return () => {
|
|
87
|
+
subscription.remove();
|
|
88
|
+
clearInterval(intervalId);
|
|
89
|
+
}
|
|
90
|
+
}, [resetTimer, appState, lastTimestamp]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => { }, [])
|
|
93
|
+
|
|
35
94
|
return (
|
|
36
95
|
<View>
|
|
37
96
|
<Text style={style}>
|
|
38
|
-
{seconds
|
|
39
|
-
? `${minutesTemp < 10 ? `0${minutesTemp - 1}` : minutesTemp - 1}:60`
|
|
40
|
-
: `${minutesTemp < 10
|
|
41
|
-
? `0${minutesTemp - 1 === -1 ? minutesTemp : minutesTemp - 1}`
|
|
42
|
-
: minutesTemp - 1
|
|
43
|
-
}:${seconds < 10 ? `0${seconds}` : seconds}`}
|
|
97
|
+
{`${minutesTemp < 10 ? `0${minutesTemp}` : minutesTemp}:${seconds < 10 ? `0${seconds}` : seconds}`}
|
|
44
98
|
</Text>
|
|
45
99
|
</View>
|
|
46
100
|
);
|
|
47
|
-
};
|
|
101
|
+
};
|