@eohjsc/react-native-smart-city 0.5.6 → 0.5.7-rc1
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 +2 -1
- package/src/commons/ActionGroup/OnOffTemplate/OnOffButtonTemplate.js +27 -3
- package/src/commons/ActionGroup/OnOffTemplate/index.js +47 -32
- package/src/commons/ActionGroup/__test__/index.test.js +40 -1
- package/src/configs/Constants.js +5 -0
- package/src/screens/Automate/EditActionsList/UpdateNotifyScript.js +31 -29
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eohjsc/react-native-smart-city",
|
|
3
3
|
"title": "React Native Smart Home",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.7-rc1",
|
|
5
5
|
"description": "TODO",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -161,6 +161,7 @@
|
|
|
161
161
|
"react-native-bootsplash": "^2.2.5",
|
|
162
162
|
"react-native-calendars": "^1.1266.0",
|
|
163
163
|
"react-native-chart-kit": "^6.5.0",
|
|
164
|
+
"react-native-charts-wrapper": "^0.6.0",
|
|
164
165
|
"react-native-credit-card-input": "^0.4.1",
|
|
165
166
|
"react-native-crypto-aes-cbc": "^1.1.1",
|
|
166
167
|
"react-native-dash": "^0.0.11",
|
|
@@ -4,11 +4,19 @@ import React, { memo, useMemo } from 'react';
|
|
|
4
4
|
import { TouchableOpacity, View } from 'react-native';
|
|
5
5
|
import { Colors } from '../../../configs';
|
|
6
6
|
import styles from './OnOffButtonTemplateStyle';
|
|
7
|
-
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
7
|
+
import { AccessibilityLabel, BUTTON_TYPE } from '../../../configs/Constants';
|
|
8
8
|
import IconComponent from '../../IconComponent';
|
|
9
9
|
|
|
10
10
|
const OnOffButtonTemplate = memo(
|
|
11
|
-
({
|
|
11
|
+
({
|
|
12
|
+
isOn,
|
|
13
|
+
triggerAction,
|
|
14
|
+
triggerOnAction,
|
|
15
|
+
triggerOffAction,
|
|
16
|
+
actionGroup = {},
|
|
17
|
+
isLight = false,
|
|
18
|
+
item,
|
|
19
|
+
}) => {
|
|
12
20
|
const {
|
|
13
21
|
icon_on,
|
|
14
22
|
icon_off,
|
|
@@ -16,7 +24,9 @@ const OnOffButtonTemplate = memo(
|
|
|
16
24
|
icon_kit_off_data,
|
|
17
25
|
text_on,
|
|
18
26
|
text_off,
|
|
27
|
+
button_type,
|
|
19
28
|
} = actionGroup;
|
|
29
|
+
|
|
20
30
|
const icon = useMemo(() => {
|
|
21
31
|
if (isOn) {
|
|
22
32
|
return icon_kit_on_data?.icon || icon_on;
|
|
@@ -24,12 +34,26 @@ const OnOffButtonTemplate = memo(
|
|
|
24
34
|
return icon_kit_off_data?.icon || icon_off;
|
|
25
35
|
}, [isOn, icon_on, icon_off, icon_kit_on_data, icon_kit_off_data]);
|
|
26
36
|
|
|
37
|
+
const attrs = useMemo(() => {
|
|
38
|
+
if (button_type === BUTTON_TYPE.PUSH_BUTTON) {
|
|
39
|
+
return {
|
|
40
|
+
onPressIn: triggerOnAction,
|
|
41
|
+
onPressOut: triggerOffAction,
|
|
42
|
+
activeOpacity: 0.7,
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
return {
|
|
46
|
+
onPress: triggerAction,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}, [button_type, triggerAction, triggerOffAction, triggerOnAction]);
|
|
50
|
+
|
|
27
51
|
return (
|
|
28
52
|
<>
|
|
29
53
|
<View style={styles.barrierControlContainer}>
|
|
30
54
|
<TouchableOpacity
|
|
31
55
|
style={styles.bigCircle}
|
|
32
|
-
|
|
56
|
+
{...attrs}
|
|
33
57
|
accessibilityLabel={`${AccessibilityLabel.ON_OFF_BUTTON}-${item?.id}`}
|
|
34
58
|
>
|
|
35
59
|
<View style={styles.smallCircle}>
|
|
@@ -50,40 +50,53 @@ const OnOffTemplate = memo(({ item = {}, doAction, sensor = {} }) => {
|
|
|
50
50
|
|
|
51
51
|
const [isOn, setIsOn] = useState(false);
|
|
52
52
|
|
|
53
|
+
const realTrigger = useCallback(
|
|
54
|
+
async (action_data, config_value) => {
|
|
55
|
+
if (!action_data) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let data;
|
|
59
|
+
if (
|
|
60
|
+
allow_config_store_value &&
|
|
61
|
+
config &&
|
|
62
|
+
device_type !== DEVICE_TYPE.GOOGLE_HOME
|
|
63
|
+
) {
|
|
64
|
+
data = {
|
|
65
|
+
config_id: config,
|
|
66
|
+
config_value: config_value,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
await doAction(action_data, data);
|
|
70
|
+
if (
|
|
71
|
+
is_managed_by_backend &&
|
|
72
|
+
config &&
|
|
73
|
+
device_type === DEVICE_TYPE.LG_THINQ
|
|
74
|
+
) {
|
|
75
|
+
watchMultiConfigs([config]);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
[
|
|
79
|
+
allow_config_store_value,
|
|
80
|
+
config,
|
|
81
|
+
device_type,
|
|
82
|
+
doAction,
|
|
83
|
+
is_managed_by_backend,
|
|
84
|
+
]
|
|
85
|
+
);
|
|
86
|
+
|
|
53
87
|
const triggerAction = useCallback(async () => {
|
|
54
88
|
const action_data = isOn ? action_off_data : action_on_data;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
config_value: isOn ? 0 : 1,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
await doAction(action_data, data);
|
|
70
|
-
if (
|
|
71
|
-
is_managed_by_backend &&
|
|
72
|
-
config &&
|
|
73
|
-
device_type === DEVICE_TYPE.LG_THINQ
|
|
74
|
-
) {
|
|
75
|
-
watchMultiConfigs([config]);
|
|
76
|
-
}
|
|
77
|
-
}, [
|
|
78
|
-
isOn,
|
|
79
|
-
action_off_data,
|
|
80
|
-
action_on_data,
|
|
81
|
-
allow_config_store_value,
|
|
82
|
-
config,
|
|
83
|
-
device_type,
|
|
84
|
-
doAction,
|
|
85
|
-
is_managed_by_backend,
|
|
86
|
-
]);
|
|
89
|
+
const config_value = isOn ? 0 : 1;
|
|
90
|
+
realTrigger(action_data, config_value);
|
|
91
|
+
}, [isOn, action_off_data, action_on_data, realTrigger]);
|
|
92
|
+
|
|
93
|
+
const triggerOnAction = useCallback(async () => {
|
|
94
|
+
realTrigger(action_on_data, 1);
|
|
95
|
+
}, [action_on_data, realTrigger]);
|
|
96
|
+
|
|
97
|
+
const triggerOffAction = useCallback(async () => {
|
|
98
|
+
realTrigger(action_off_data, 0);
|
|
99
|
+
}, [action_off_data, realTrigger]);
|
|
87
100
|
|
|
88
101
|
useUnwatchLGDeviceConfigControl(sensor, [config]);
|
|
89
102
|
|
|
@@ -100,6 +113,8 @@ const OnOffTemplate = memo(({ item = {}, doAction, sensor = {} }) => {
|
|
|
100
113
|
<Component
|
|
101
114
|
isOn={isOn}
|
|
102
115
|
triggerAction={triggerAction}
|
|
116
|
+
triggerOnAction={triggerOnAction}
|
|
117
|
+
triggerOffAction={triggerOffAction}
|
|
103
118
|
actionGroup={configuration}
|
|
104
119
|
disabled={!action_on_data && !action_off_data}
|
|
105
120
|
item={item}
|
|
@@ -11,7 +11,7 @@ import moment from 'moment';
|
|
|
11
11
|
|
|
12
12
|
import ActionGroup from '..';
|
|
13
13
|
import Text from '../../Text';
|
|
14
|
-
import { AccessibilityLabel } from '../../../configs/Constants';
|
|
14
|
+
import { AccessibilityLabel, BUTTON_TYPE } from '../../../configs/Constants';
|
|
15
15
|
import { SCProvider } from '../../../context';
|
|
16
16
|
import { mockSCStore } from '../../../context/mockStore';
|
|
17
17
|
import { Slider } from '@miblanchard/react-native-slider';
|
|
@@ -347,6 +347,45 @@ describe('Test ActionGroup', () => {
|
|
|
347
347
|
expect(mockDoAction).toHaveBeenCalledTimes(1);
|
|
348
348
|
});
|
|
349
349
|
|
|
350
|
+
it('render ActionGroup on_off_button_action_template button type push button', async () => {
|
|
351
|
+
const mockDoAction = jest.fn();
|
|
352
|
+
const actionGroup = {
|
|
353
|
+
template: 'on_off_button_action_template',
|
|
354
|
+
configuration: {
|
|
355
|
+
action_on_data: 'action_on_data',
|
|
356
|
+
action_off_data: 'action_off_data',
|
|
357
|
+
icon_on: 'caret-up',
|
|
358
|
+
text_on: 'ON',
|
|
359
|
+
icon_off: 'caret-up',
|
|
360
|
+
text_off: 'OFF',
|
|
361
|
+
button_type: BUTTON_TYPE.PUSH_BUTTON,
|
|
362
|
+
},
|
|
363
|
+
title: 'Power',
|
|
364
|
+
};
|
|
365
|
+
await act(async () => {
|
|
366
|
+
wrapper = renderer.create(
|
|
367
|
+
wrapComponent(actionGroup, mockDoAction, sensor)
|
|
368
|
+
);
|
|
369
|
+
});
|
|
370
|
+
const instance = wrapper.root;
|
|
371
|
+
const buttons = instance.findAllByType(TouchableOpacity);
|
|
372
|
+
expect(buttons.length).toEqual(1);
|
|
373
|
+
await act(async () => {
|
|
374
|
+
buttons[0].props.onPressIn();
|
|
375
|
+
});
|
|
376
|
+
expect(mockDoAction).toHaveBeenCalledWith(
|
|
377
|
+
actionGroup.configuration.action_on_data,
|
|
378
|
+
undefined
|
|
379
|
+
);
|
|
380
|
+
await act(async () => {
|
|
381
|
+
buttons[0].props.onPressOut();
|
|
382
|
+
});
|
|
383
|
+
expect(mockDoAction).toHaveBeenCalledWith(
|
|
384
|
+
actionGroup.configuration.action_off_data,
|
|
385
|
+
undefined
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
|
|
350
389
|
it('render ActionGroup NumberUpDownActionTemplate watch config value null', async () => {
|
|
351
390
|
const mockDoAction = jest.fn();
|
|
352
391
|
const actionGroup = {
|
package/src/configs/Constants.js
CHANGED
|
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo, useState } from 'react';
|
|
|
2
2
|
import _TextInput from '../../../commons/Form/TextInput';
|
|
3
3
|
import styles from './Styles/indexStyles';
|
|
4
4
|
import AccessibilityLabel from '../../../configs/AccessibilityLabel';
|
|
5
|
-
import { View } from 'react-native';
|
|
5
|
+
import { Keyboard, TouchableWithoutFeedback, View } from 'react-native';
|
|
6
6
|
import { axiosPut } from '../../../utils/Apis/axios';
|
|
7
7
|
import { API } from '../../../configs';
|
|
8
8
|
import { ToastBottomHelper } from '../../../utils/Utils';
|
|
@@ -77,36 +77,38 @@ const UpdateNotifyScript = ({
|
|
|
77
77
|
}, [message, newValue, title]);
|
|
78
78
|
|
|
79
79
|
return (
|
|
80
|
-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
<_TextInput
|
|
91
|
-
label={t('update_message_notification')}
|
|
92
|
-
placeholder={t('message_notification')}
|
|
93
|
-
onChange={onChangeMessage}
|
|
94
|
-
textInputStyle={styles.textMessage}
|
|
95
|
-
value={newValue.newMessage}
|
|
96
|
-
accessibilityLabel={AccessibilityLabel.AUTOMATE_MESSAGE_NOTIFY}
|
|
97
|
-
multiline={true}
|
|
98
|
-
maxLength={255}
|
|
99
|
-
/>
|
|
100
|
-
<View style={styles.wrapBottom}>
|
|
101
|
-
<BottomButtonView
|
|
102
|
-
mainTitle={t('update_now')}
|
|
103
|
-
onPressMain={onPressSave}
|
|
104
|
-
typeMain={canSave ? 'primary' : 'disabled'}
|
|
105
|
-
accessibilityLabel={AccessibilityLabel.BUTTON_SAVE_EDIT_ACTION_LIST}
|
|
106
|
-
disableKeyBoardAnimated
|
|
80
|
+
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
|
|
81
|
+
<View>
|
|
82
|
+
<_TextInput
|
|
83
|
+
label={t('update_title_notification')}
|
|
84
|
+
placeholder={t('title_notification')}
|
|
85
|
+
onChange={onChangeTitle}
|
|
86
|
+
textInputStyle={styles.textTitle}
|
|
87
|
+
value={newValue.newTitle}
|
|
88
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_TITLE_NOTIFY}
|
|
89
|
+
autoFocus
|
|
107
90
|
/>
|
|
91
|
+
<_TextInput
|
|
92
|
+
label={t('update_message_notification')}
|
|
93
|
+
placeholder={t('message_notification')}
|
|
94
|
+
onChange={onChangeMessage}
|
|
95
|
+
textInputStyle={styles.textMessage}
|
|
96
|
+
value={newValue.newMessage}
|
|
97
|
+
accessibilityLabel={AccessibilityLabel.AUTOMATE_MESSAGE_NOTIFY}
|
|
98
|
+
multiline={true}
|
|
99
|
+
maxLength={255}
|
|
100
|
+
/>
|
|
101
|
+
<View style={styles.wrapBottom}>
|
|
102
|
+
<BottomButtonView
|
|
103
|
+
mainTitle={t('update_now')}
|
|
104
|
+
onPressMain={onPressSave}
|
|
105
|
+
typeMain={canSave ? 'primary' : 'disabled'}
|
|
106
|
+
accessibilityLabel={AccessibilityLabel.BUTTON_SAVE_EDIT_ACTION_LIST}
|
|
107
|
+
disableKeyBoardAnimated
|
|
108
|
+
/>
|
|
109
|
+
</View>
|
|
108
110
|
</View>
|
|
109
|
-
|
|
111
|
+
</TouchableWithoutFeedback>
|
|
110
112
|
);
|
|
111
113
|
};
|
|
112
114
|
|