@eohjsc/react-native-smart-city 0.3.91 → 0.3.93

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.
Files changed (237) hide show
  1. package/package.json +5 -1
  2. package/src/Images/Common/reorder.svg +3 -0
  3. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/AutoLockStyles.js +1 -1
  4. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/__test__/index.test.js +3 -1
  5. package/src/commons/ActionGroup/OnOffSmartLock/AutoLock/index.js +3 -3
  6. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/__test__/index.test.js +3 -10
  7. package/src/commons/ActionGroup/OnOffSmartLock/PasscodeList/index.js +1 -0
  8. package/src/commons/ActionGroup/OnOffSmartLock/SetupGeneratePasscode/SetupGeneratePasscodeStyles.js +1 -1
  9. package/src/commons/ActionGroup/OnOffTemplate/SwitchButtonTemplate.js +13 -5
  10. package/src/commons/ActionGroup/SliderRangeTemplate.js +100 -69
  11. package/src/commons/ActionGroup/SliderRangeTemplateStyles.js +27 -27
  12. package/src/commons/ActionGroup/StatesGridActionTemplate.js +4 -1
  13. package/src/commons/ActionGroup/__test__/OnOffTemplate.test.js +4 -1
  14. package/src/commons/ActionGroup/__test__/SliderRangeTemplate.test.js +56 -0
  15. package/src/commons/ActionGroup/__test__/StatesGridActionTemplate.test.js +2 -2
  16. package/src/commons/ActionGroup/__test__/SwitchButtonTemplate.test.js +45 -8
  17. package/src/commons/ActionGroup/__test__/index.test.js +0 -19
  18. package/src/commons/ActionGroup/index.js +0 -3
  19. package/src/commons/ActionTemplate/CurtainAction.js +3 -3
  20. package/src/commons/ActionTemplate/CurtainActionStyles.js +1 -1
  21. package/src/commons/ActionTemplate/OnOffButtonAction.js +2 -2
  22. package/src/commons/ActionTemplate/OnOffButtonActionStyles.js +1 -1
  23. package/src/commons/ActionTemplate/OnOffSimpleAction.js +2 -2
  24. package/src/commons/ActionTemplate/OnOffSimpleActionStyles.js +1 -1
  25. package/src/commons/ActionTemplate/OnOffSmartLockAction.js +2 -2
  26. package/src/commons/ActionTemplate/OnOffSmartLockActionStyles.js +1 -1
  27. package/src/commons/ActionTemplate/OneButtonAction.js +1 -1
  28. package/src/commons/ActionTemplate/OneButtonActionStyles.js +1 -1
  29. package/src/commons/ActionTemplate/ThreeButtonAction.js +3 -3
  30. package/src/commons/ActionTemplate/ThreeButtonActionStyles.js +1 -1
  31. package/src/commons/AlertAction/index.js +5 -0
  32. package/src/commons/Auth/AccountList.js +1 -1
  33. package/src/commons/Auth/__test__/OtpInputList.test.js +13 -17
  34. package/src/commons/Automate/ItemAutomate.js +10 -4
  35. package/src/commons/Automate/__test__/ItemAutomate.test.js +11 -11
  36. package/src/commons/BottomButtonView/index.js +22 -4
  37. package/src/commons/Button/index.js +5 -0
  38. package/src/commons/Device/ConnectedViewHeader.js +0 -1
  39. package/src/commons/Device/DeviceAlertStatus.js +2 -1
  40. package/src/commons/Device/Emergency/EmergencyDetail.js +4 -2
  41. package/src/commons/Device/Emergency/__test__/EmergencyDetail.test.js +4 -2
  42. package/src/commons/Device/ProgressBar/index.js +7 -11
  43. package/src/commons/Device/ProgressBar/styles.js +9 -4
  44. package/src/commons/Device/WindSpeed/Anemometer/index.js +3 -1
  45. package/src/commons/Device/WindSpeed/LinearChart/__test__/LinearChart.test.js +14 -1
  46. package/src/commons/Device/WindSpeed/LinearChart/index.js +4 -2
  47. package/src/commons/FlatListDnD/__test__/index.test.js +49 -0
  48. package/src/commons/FlatListDnD/index.js +37 -0
  49. package/src/commons/FlatListDnD/styles.js +12 -0
  50. package/src/commons/Form/__test__/TextInput.test.js +1 -1
  51. package/src/commons/Header/HeaderCustom.js +10 -19
  52. package/src/commons/HorizontalPicker/index.js +65 -38
  53. package/src/commons/IconComponent/index.js +3 -2
  54. package/src/commons/MediaPlayer/__test__/index.test.js +8 -3
  55. package/src/commons/MediaPlayer/index.js +11 -7
  56. package/src/commons/MenuActionMore/index.js +6 -4
  57. package/src/commons/Modal/ModalBottom.js +2 -3
  58. package/src/commons/Modal/ModalCustom.js +2 -3
  59. package/src/commons/NavBar/index.js +48 -50
  60. package/src/commons/OneTapTemplate/NumberUpDownActionTemplate.js +1 -1
  61. package/src/commons/OneTapTemplate/NumberUpDownActionTemplateStyles.js +1 -1
  62. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplate.js +1 -1
  63. package/src/commons/OneTapTemplate/OptionsDropdownActionTemplateStyles.js +1 -1
  64. package/src/commons/OneTapTemplate/StatesGridActionTemplate.js +1 -1
  65. package/src/commons/OneTapTemplate/StatesGridActionTemplateStyles.js +1 -1
  66. package/src/commons/PreventAccess/index.js +1 -1
  67. package/src/commons/Sharing/StationDevicePermissions.js +4 -4
  68. package/src/commons/Sharing/WrapHeaderScrollable.js +5 -5
  69. package/src/commons/Sharing/__test__/DevicePermissionsCheckbox.test.js +2 -2
  70. package/src/commons/SubUnit/OneTap/ItemOneTap.js +12 -59
  71. package/src/commons/SubUnit/OneTap/__test__/SubUnitAutomate.test.js +16 -20
  72. package/src/commons/SubUnit/OneTap/index.js +20 -7
  73. package/src/commons/UnitSummary/AirQuality/__test__/index.test.js +4 -0
  74. package/src/commons/UnitSummary/ConfigHistoryChart/__test__/ConfigHistoryChart.test.js +1 -1
  75. package/src/commons/ViewButtonBottom/index.js +32 -4
  76. package/src/configs/API.js +9 -0
  77. package/src/configs/AccessibilityLabel.js +2 -0
  78. package/src/configs/BLE.js +1 -0
  79. package/src/configs/Colors.js +1 -1
  80. package/src/configs/Constants.js +12 -18
  81. package/src/context/actionType.ts +2 -1
  82. package/src/context/mockStore.ts +1 -0
  83. package/src/context/reducer.ts +12 -1
  84. package/src/hooks/Common/__test__/useStatusbar.test.js +5 -5
  85. package/src/hooks/Common/index.js +0 -2
  86. package/src/hooks/Common/useKeyboardShow.js +4 -4
  87. package/src/hooks/Common/useStatusBar.js +2 -2
  88. package/src/hooks/Common/useTitleHeader.js +5 -7
  89. package/src/hooks/Explore/useKeyboardAnimated.js +10 -4
  90. package/src/hooks/IoT/__test__/useRemoteControl.test.js +11 -0
  91. package/src/hooks/IoT/useBluetoothConnection.js +20 -29
  92. package/src/hooks/index.js +1 -2
  93. package/src/hooks/useMqtt.js +95 -0
  94. package/src/iot/Monitor.js +2 -1
  95. package/src/iot/RemoteControl/Bluetooth.js +56 -19
  96. package/src/iot/RemoteControl/__test__/Bluetooth.test.js +140 -0
  97. package/src/iot/mqtt.js +233 -0
  98. package/src/navigations/UnitStack.js +44 -12
  99. package/src/screens/AddLocationMaps/index.js +18 -16
  100. package/src/screens/AddLocationMaps/indexStyle.js +3 -0
  101. package/src/screens/AddNewGateway/SelectDeviceSubUnit.js +1 -2
  102. package/src/screens/AddNewGateway/__test__/AddNewGateway.test.js +5 -17
  103. package/src/screens/AddNewGateway/__test__/SelectDeviceSubUnit.test.js +5 -13
  104. package/src/screens/AddNewGateway/__test__/SelectDeviceUnit.test.js +9 -11
  105. package/src/screens/AddNewGateway/__test__/SelectModbusGateway.test.js +6 -14
  106. package/src/screens/AddNewGateway/__test__/SelectZigbeeGateway.test.js +6 -14
  107. package/src/screens/AddNewGateway/hooks/__Tests__/useWifiManage.test.js +3 -2
  108. package/src/screens/AddNewGateway/index.js +1 -1
  109. package/src/screens/AllCamera/index.js +2 -3
  110. package/src/screens/AllGateway/DetailConfigActionZigbee/__test__/index.test.js +0 -18
  111. package/src/screens/AllGateway/DetailConfigActionZigbee/index.js +1 -1
  112. package/src/screens/AllGateway/DeviceModbusDetail/__test__/index.test.js +5 -2
  113. package/src/screens/AllGateway/hooks/__test__/index.test.js +1 -1
  114. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseAction.js +78 -119
  115. package/src/screens/{AddNewAction → Automate/AddNewAction}/ChooseConfig.js +45 -73
  116. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/LoadingSelectAction.js +1 -1
  117. package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/SelectDevices.js +3 -3
  118. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/DeviceStyles.js +5 -1
  119. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/__test__/index.test.js +3 -3
  120. package/src/screens/{AddNewAction → Automate/AddNewAction}/Device/index.js +5 -4
  121. package/src/screens/{AddNewAction → Automate/AddNewAction}/NewActionWrapper.js +5 -7
  122. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectControlDevices.js +11 -49
  123. package/src/screens/{AddNewAction → Automate/AddNewAction}/SelectMonitorDevices.js +10 -42
  124. package/src/screens/{AddNewAction → Automate/AddNewAction}/SetupConfigCondition.js +52 -101
  125. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectActionStyles.js +1 -1
  126. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SelectSensorDevicesStyles.js +1 -1
  127. package/src/screens/{AddNewAction → Automate/AddNewAction}/Styles/SetupSensorStyles.js +4 -2
  128. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseAction.test.js +10 -11
  129. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/ChooseConfig.test.js +26 -27
  130. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectControlDevices.test.js +9 -9
  131. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SelectMonitorDevices.test.js +5 -5
  132. package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/SetupSensor.test.js +52 -16
  133. package/src/screens/Automate/AddNewAutoSmart/AddAutomationTypeSmart.js +25 -0
  134. package/src/screens/Automate/AddNewAutoSmart/AddTypeSmart.js +78 -0
  135. package/src/screens/Automate/AddNewAutoSmart/AddUnknownTypeSmart.js +29 -0
  136. package/src/screens/{AddNewAutoSmart → Automate/AddNewAutoSmart}/__test__/AddNewAutoSmart.test.js +18 -41
  137. package/src/screens/{AddNewAutoSmart → Automate/AddNewAutoSmart}/styles/AddNewAutoSmartStyles.js +1 -1
  138. package/src/screens/Automate/Components/InputName.js +64 -0
  139. package/src/screens/{AddNewOneTap/AddNewOneTapStyles.js → Automate/Components/InputNameStyles.js} +3 -3
  140. package/src/screens/{EditActionsList → Automate/EditActionsList}/Styles/indexStyles.js +5 -1
  141. package/src/screens/{EditActionsList → Automate/EditActionsList}/__tests__/index.test.js +17 -31
  142. package/src/screens/{EditActionsList → Automate/EditActionsList}/index.js +49 -51
  143. package/src/screens/Automate/MultiUnits.js +69 -67
  144. package/src/screens/Automate/OneTap/__test__/AddNewOneTap.test.js +134 -0
  145. package/src/screens/Automate/OneTap/index.js +16 -0
  146. package/src/screens/Automate/Scenario/ScenarioName.js +15 -0
  147. package/src/screens/{AddNewOneTap → Automate/Scenario}/__test__/AddNewOneTap.test.js +27 -45
  148. package/src/screens/Automate/ScriptDetail/Components/DeleteScript.js +45 -0
  149. package/src/screens/Automate/ScriptDetail/Components/RenameScript.js +58 -0
  150. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/Styles/indexStyles.js +1 -1
  151. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/index.test.js +110 -74
  152. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/__test__/useStarredScript.test.js +7 -6
  153. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/hooks/useStarredScript.js +4 -4
  154. package/src/screens/Automate/ScriptDetail/index.js +360 -0
  155. package/src/screens/{ScriptDetail → Automate/ScriptDetail}/utils.js +32 -31
  156. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/SelectWeekday.test.js +2 -2
  157. package/src/screens/{SetSchedule → Automate/SetSchedule}/__test__/index.test.js +21 -46
  158. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RepeatOptionsPopup.js +4 -4
  159. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/RowItem.js +2 -2
  160. package/src/screens/{SetSchedule → Automate/SetSchedule}/components/SelectWeekday.js +3 -3
  161. package/src/screens/Automate/SetSchedule/index.js +140 -0
  162. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RepeatOptionsPopupStyles.js +1 -1
  163. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/RowItemStyles.js +1 -1
  164. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/SelectWeekdayStyles.js +1 -1
  165. package/src/screens/{SetSchedule → Automate/SetSchedule}/styles/indexStyles.js +1 -1
  166. package/src/screens/Automate/ValueChange/ValueChangeName.js +16 -0
  167. package/src/screens/Automate/__test__/MultiUnits.test.js +77 -121
  168. package/src/screens/Automate/__test__/index.test.js +3 -10
  169. package/src/screens/Automate/constants.js +0 -0
  170. package/src/screens/Automate/index.js +12 -23
  171. package/src/screens/ChangePosition/__test__/index.test.js +75 -0
  172. package/src/screens/ChangePosition/index.js +112 -0
  173. package/src/screens/ChangePosition/styles.js +87 -0
  174. package/src/screens/Device/__test__/detail.test.js +203 -258
  175. package/src/screens/Device/__test__/mqttDetail.test.js +599 -0
  176. package/src/screens/Device/__test__/sensorDisplayItem.test.js +4 -0
  177. package/src/screens/Device/components/SensorDisplayItem.js +3 -8
  178. package/src/screens/Device/components/VisualChart.js +55 -8
  179. package/src/screens/Device/detail.js +78 -30
  180. package/src/screens/Device/hooks/__test__/useEmergencyButton.test.js +35 -13
  181. package/src/screens/Device/hooks/useDeviceWatchConfigControl.js +13 -3
  182. package/src/screens/Device/hooks/useEvaluateValue.js +20 -2
  183. package/src/screens/Device/styles.js +7 -0
  184. package/src/screens/GuestInfo/components/__test__/AccessScheduleSheet.test.js +52 -0
  185. package/src/screens/MoveToAnotherSubUnit/__test__/index.test.js +18 -13
  186. package/src/screens/Notification/__test__/Notification.test.js +1 -1
  187. package/src/screens/PlayBackCamera/index.js +2 -3
  188. package/src/screens/SelectUnit/__test__/index.test.js +8 -13
  189. package/src/screens/SharedUnit/index.js +5 -4
  190. package/src/screens/Sharing/SelectUser.js +2 -2
  191. package/src/screens/Sharing/__test__/MemberList.test.js +9 -15
  192. package/src/screens/Sharing/__test__/MemberList2.test.js +10 -16
  193. package/src/screens/Sharing/__test__/SelectUser.test.js +8 -4
  194. package/src/screens/SideMenuDetail/SideMenuDetailStyles.js +1 -1
  195. package/src/screens/SmartAccount/__test__/SmartAccount.test.js +8 -4
  196. package/src/screens/SmartAccount/index.js +9 -9
  197. package/src/screens/SmartAccount/style.js +8 -7
  198. package/src/screens/SubUnit/ManageSubUnit.js +4 -4
  199. package/src/screens/SubUnit/__test__/ManageSubUnit.test.js +9 -28
  200. package/src/screens/TDSGuide/index.js +1 -1
  201. package/src/screens/Template/GatewayList.js +4 -1
  202. package/src/screens/Template/__test__/detail.test.js +14 -20
  203. package/src/screens/Template/detail.js +1 -0
  204. package/src/screens/UVIndexGuide/index.js +2 -2
  205. package/src/screens/Unit/Detail.js +10 -24
  206. package/src/screens/Unit/SelectAddToFavorites.js +1 -1
  207. package/src/screens/Unit/Summaries.js +6 -17
  208. package/src/screens/Unit/__test__/ChooseLocation.test.js +8 -13
  209. package/src/screens/Unit/__test__/Detail.test.js +3 -1
  210. package/src/screens/Unit/__test__/SelectAddToFavorites.test.js +1 -1
  211. package/src/screens/Unit/__test__/SmartAccount.test.js +8 -14
  212. package/src/screens/Unit/__test__/Summaries.test.js +2 -2
  213. package/src/screens/UnitSummary/components/UvIndex/__test__/index.test.js +4 -0
  214. package/src/screens/UnitSummary/components/WaterQuality/__test__/index.test.js +6 -11
  215. package/src/screens/WaterQualityGuide/index.js +10 -5
  216. package/src/utils/FactoryGateway.js +525 -0
  217. package/src/utils/I18n/translations/en.json +28 -19
  218. package/src/utils/I18n/translations/vi.json +26 -20
  219. package/src/utils/Route/index.js +5 -1
  220. package/src/utils/Utils.js +40 -0
  221. package/src/utils/__test__/Utils.test.js +6 -0
  222. package/src/commons/ActionGroup/CurtainButtonTemplate.js +0 -130
  223. package/src/commons/ActionGroup/__test__/CurtainButtonTemplate.test.js +0 -109
  224. package/src/commons/Auth/SocialButton.js +0 -54
  225. package/src/commons/Auth/__test__/SocialButton.test.js +0 -46
  226. package/src/commons/Device/SensorConnectedStatus.js +0 -56
  227. package/src/commons/Device/__test__/SensorConnectedStatus.test.js +0 -29
  228. package/src/commons/Sharing/__test__/StationDevicePermission.test.js +0 -85
  229. package/src/hooks/__test__/useInitDeepLink.test.js +0 -28
  230. package/src/hooks/useInitDeepLink.js +0 -25
  231. package/src/screens/AddNewAutoSmart/index.js +0 -149
  232. package/src/screens/AddNewOneTap/index.js +0 -156
  233. package/src/screens/ScriptDetail/hooks/index.js +0 -136
  234. package/src/screens/ScriptDetail/index.js +0 -446
  235. package/src/screens/SetSchedule/index.js +0 -200
  236. /package/src/screens/{AddNewAction → Automate/AddNewAction}/Components/index.js +0 -0
  237. /package/src/screens/{AddNewAction → Automate/AddNewAction}/__test__/LoadingSelectAction.test.js +0 -0
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.3.91",
4
+ "version": "0.3.93",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -129,6 +129,7 @@
129
129
  "@testing-library/react-hooks": "^6.0.0",
130
130
  "apisauce": "^2.1.5",
131
131
  "axios": "^0.19.2",
132
+ "base-64": "^1.0.0",
132
133
  "deprecated-react-native-prop-types": "^2.3.0",
133
134
  "dotenv": "^8.2.0",
134
135
  "google-libphonenumber": "^3.2.10",
@@ -143,8 +144,10 @@
143
144
  "patch-package": "^6.2.2",
144
145
  "pluralize": "^8.0.0",
145
146
  "postinstall": "^0.7.0",
147
+ "precompiled-mqtt": "^4.3.14-beta",
146
148
  "pusher-js": "^7.4.0",
147
149
  "pusher-js-auth": "^4.0.1",
150
+ "python-struct": "^1.1.3",
148
151
  "querystring": "^0.2.0",
149
152
  "react-content-loader": "^6.0.3",
150
153
  "react-dom": "^17.0.1",
@@ -161,6 +164,7 @@
161
164
  "react-native-calendars": "^1.1266.0",
162
165
  "react-native-chart-kit": "^6.5.0",
163
166
  "react-native-credit-card-input": "^0.4.1",
167
+ "react-native-crypto-aes-cbc": "^1.1.1",
164
168
  "react-native-dash": "^0.0.11",
165
169
  "react-native-deep-linking": "^2.2.0",
166
170
  "react-native-device-info": "^10.3.0",
@@ -0,0 +1,3 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M3 15H21V13H3V15ZM3 19H21V17H3V19ZM3 11H21V9H3V11ZM3 5V7H21V5H3Z" fill="#262626"/>
3
+ </svg>
@@ -18,7 +18,7 @@ export default StyleSheet.create({
18
18
  textYourDoor: {
19
19
  fontSize: 12,
20
20
  color: Colors.Gray8,
21
- maginBottom: 16,
21
+ marginBottom: 16,
22
22
  },
23
23
  slider: {
24
24
  marginTop: 20,
@@ -46,7 +46,9 @@ describe('Test AutoLock', () => {
46
46
 
47
47
  const instance = tree.root;
48
48
  const switchs = instance.findByType(Switch);
49
- await switchs.props.onValueChange();
49
+ await act(async () => {
50
+ await switchs.props.onValueChange();
51
+ });
50
52
 
51
53
  const { buttonEnable, buttonInstant, buttonRelockTiming } =
52
54
  getElement(instance);
@@ -1,4 +1,4 @@
1
- import React, { memo, useCallback, useState } from 'react';
1
+ import React, { useCallback, useState } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import { Slider } from '@miblanchard/react-native-slider';
4
4
  import Text from '../../../Text';
@@ -9,7 +9,7 @@ import styles from './AutoLockStyles';
9
9
  import t from '../../../../hooks/Common/useTranslations';
10
10
  import { Colors } from '../../../../configs';
11
11
 
12
- const AutoLock = memo(() => {
12
+ const AutoLock = () => {
13
13
  const [isEnabled, setIsEnabled] = useState(false);
14
14
 
15
15
  const handleToggleSwitch = useCallback(() => {
@@ -52,6 +52,6 @@ const AutoLock = memo(() => {
52
52
  </View>
53
53
  </View>
54
54
  );
55
- });
55
+ };
56
56
 
57
57
  export default AutoLock;
@@ -7,16 +7,7 @@ import { SCProvider } from '../../../../../context';
7
7
  import PasscodeList from '../index';
8
8
  import { TouchableOpacity } from 'react-native';
9
9
  import Routes from '../../../../../utils/Route';
10
-
11
- const mockNavigate = jest.fn();
12
- jest.mock('@react-navigation/native', () => {
13
- return {
14
- ...jest.requireActual('@react-navigation/native'),
15
- useNavigation: () => ({
16
- navigate: mockNavigate,
17
- }),
18
- };
19
- });
10
+ import { useNavigation } from '@react-navigation/native';
20
11
 
21
12
  const wrapComponent = () => (
22
13
  <SCProvider initState={mockSCStore({})}>
@@ -27,6 +18,8 @@ const wrapComponent = () => (
27
18
  describe('Test SetupGeneratePasscode', () => {
28
19
  let tree;
29
20
 
21
+ const mockNavigate = useNavigation().navigate;
22
+
30
23
  beforeEach(() => {
31
24
  mockNavigate.mockClear();
32
25
  });
@@ -52,6 +52,7 @@ const PasscodeList = memo(() => {
52
52
  onPress={handleClickButton(item)}
53
53
  style={styles.buttonWrapper}
54
54
  accessibilityLabel={AccessibilityLabel.PASSCODE_LIST}
55
+ key={item.code}
55
56
  >
56
57
  <View>
57
58
  <Text style={styles.textCode}>{item.code}</Text>
@@ -89,7 +89,7 @@ export default StyleSheet.create({
89
89
  bottom: 0,
90
90
  left: 0,
91
91
  right: 0,
92
- paddingBottom: getBottomSpace() > 0 ? getBottomSpace() : 32,
92
+ paddingBottom: getBottomSpace() || 32,
93
93
  paddingTop: 29,
94
94
  backgroundColor: Colors.White,
95
95
  borderColor: Colors.ShadownTransparent,
@@ -1,15 +1,14 @@
1
- import React, { memo, useCallback, useState } from 'react';
1
+ import React, { memo, useCallback, useEffect, useState } from 'react';
2
2
  import { Switch, View } from 'react-native';
3
3
 
4
4
  import Text from '../../Text';
5
5
  import { Colors } from '../../../configs';
6
6
  import styles from './OnOffButtonTemplateStyle';
7
7
  import AccessibilityLabel from '../../../configs/AccessibilityLabel';
8
+ import { useConfigGlobalState } from '../../../iot/states';
8
9
 
9
10
  const SwitchButtonTemplate = memo(
10
- ({ isOn, triggerAction, actionGroup = {}, isLight = false, doAction }) => {
11
- const [_isOn, setIsOn] = useState(isOn);
12
-
11
+ ({ actionGroup = {}, isLight = false, doAction }) => {
13
12
  const { configuration = {}, id } = actionGroup;
14
13
  const {
15
14
  action_off_data,
@@ -18,8 +17,13 @@ const SwitchButtonTemplate = memo(
18
17
  text_off,
19
18
  color_on,
20
19
  color_off,
20
+ config,
21
21
  } = configuration;
22
22
 
23
+ const [configValues] = useConfigGlobalState('configValues');
24
+ const configValue = configValues[config];
25
+ const [_isOn, setIsOn] = useState(configValue?.value);
26
+
23
27
  const onChangeSwitch = useCallback(() => {
24
28
  if (_isOn) {
25
29
  setIsOn(false);
@@ -30,6 +34,10 @@ const SwitchButtonTemplate = memo(
30
34
  setIsOn(true);
31
35
  }, [action_off_data, action_on_data, doAction, _isOn]);
32
36
 
37
+ useEffect(() => {
38
+ configValue && setIsOn(configValue?.value);
39
+ }, [configValue]);
40
+
33
41
  return (
34
42
  <>
35
43
  <View style={styles.barrierControlContainer}>
@@ -37,7 +45,7 @@ const SwitchButtonTemplate = memo(
37
45
  trackColor={{ false: color_off, true: color_on }}
38
46
  ios_backgroundColor={_isOn ? color_on : color_off}
39
47
  onValueChange={onChangeSwitch}
40
- value={_isOn}
48
+ value={!!_isOn}
41
49
  />
42
50
  <Text
43
51
  style={[
@@ -1,91 +1,122 @@
1
- import React, { memo, useCallback, useState, useEffect } from 'react';
1
+ import React, {
2
+ memo,
3
+ useCallback,
4
+ useState,
5
+ useEffect,
6
+ useMemo,
7
+ useRef,
8
+ } from 'react';
9
+ import { Slider } from '@miblanchard/react-native-slider';
10
+
2
11
  import { View } from 'react-native';
3
12
  import { useTranslations } from '../../hooks/Common/useTranslations';
4
13
  import styles from './SliderRangeTemplateStyles';
5
14
  import Text from '../Text';
6
15
  import { Colors } from '../../configs';
7
- import SvgBrightness from '../../../assets/images/brightness.svg';
8
- import { Slider } from '@miblanchard/react-native-slider';
9
16
  import { useConfigGlobalState } from '../../iot/states';
10
17
  import { DEVICE_TYPE } from '../../configs/Constants';
18
+ import _TextInput from '../Form/TextInput';
19
+
20
+ const SliderRangeTemplate = memo(
21
+ ({ actionGroup = {}, doAction, sensor, item }) => {
22
+ const t = useTranslations();
23
+ const { configuration = {} } = actionGroup;
24
+ const [configValues] = useConfigGlobalState('configValues');
25
+ const {
26
+ config = undefined,
27
+ min_value = 0,
28
+ max_value = 100,
29
+ action_data,
30
+ } = configuration;
31
+ const timeout = useRef(null);
11
32
 
12
- let percentTemp = 0;
13
- const SliderRangeTemplate = memo(({ actionGroup = {}, doAction, sensor }) => {
14
- const t = useTranslations();
15
- const { configuration = {} } = actionGroup;
16
- const [configValues] = useConfigGlobalState('configValues');
17
- const { config = undefined } = configuration;
33
+ const getPercent = useCallback(() => {
34
+ return configValues[config]?.value || 0;
35
+ }, [config, configValues]);
18
36
 
19
- const getPercent = useCallback(() => {
20
- const { value } = configValues[config] || { value: 0 };
21
- return value;
22
- }, [config, configValues]);
37
+ const [valueBrightness, setValueBrightness] = useState(getPercent());
38
+
39
+ const onChangeBrightness = useCallback(
40
+ async (value) => {
41
+ const value_brness = value[0];
42
+ await doAction(
43
+ action_data,
44
+ JSON.stringify({ value_brness: value_brness, value: value_brness })
45
+ );
46
+ },
47
+ [action_data, doAction]
48
+ );
49
+
50
+ useEffect(() => {
51
+ const value = configValues[config]?.value || 0;
52
+ if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
53
+ setValueBrightness(value);
54
+ }
55
+ }, [config, configValues, sensor?.device_type]);
23
56
 
24
- const [valueBrightness, setValueBrightness] = useState(getPercent());
25
- const [isFirstTime, setIsFirstTime] = useState(true);
57
+ const getTextInputValue = useMemo(() => {
58
+ if ([null, undefined, NaN].includes(valueBrightness)) {
59
+ return 0;
60
+ }
26
61
 
27
- const onChangeBrightness = useCallback(
28
- async (value) => {
29
- const value_brness = value[0];
30
- await doAction(
31
- configuration?.action_data,
32
- JSON.stringify({ value_brness: value_brness, value: value_brness })
33
- );
34
- },
35
- [configuration?.action_data, doAction]
36
- );
62
+ return valueBrightness;
63
+ }, [valueBrightness]);
37
64
 
38
- useEffect(() => {
39
- percentTemp = valueBrightness;
40
- }, [valueBrightness]);
65
+ const onValueChange = (value) => setValueBrightness(value[0]);
41
66
 
42
- useEffect(() => {
43
- const { value } = configValues[config] || { value: 0 };
44
- if (value && isFirstTime) {
67
+ const onInputChange = (value) => {
68
+ if (isNaN(value)) {
69
+ return;
70
+ }
45
71
  setValueBrightness(value);
46
- setIsFirstTime(false);
47
- return;
48
- }
49
- if (sensor?.device_type !== DEVICE_TYPE.LG_THINQ) {
50
- if (percentTemp !== value) {
51
- setValueBrightness(value);
72
+ if (timeout.current) {
73
+ clearTimeout(timeout.current);
52
74
  }
53
- percentTemp = value;
54
- }
55
- // eslint-disable-next-line react-hooks/exhaustive-deps
56
- }, [configValues]);
75
+ if (value !== '') {
76
+ timeout.current = setTimeout(() => {
77
+ doAction(
78
+ action_data,
79
+ JSON.stringify({
80
+ value_brness: parseInt(value, 10),
81
+ value: parseInt(value, 10),
82
+ })
83
+ );
84
+ }, 300);
85
+ }
86
+ };
57
87
 
58
- return (
59
- <View style={styles.viewBrightness}>
60
- <View style={styles.LeftBrightness}>
61
- <SvgBrightness />
88
+ return (
89
+ <View style={styles.viewBrightness}>
62
90
  <Text type="H4" style={styles.LeftTextBrightness}>
63
- {actionGroup.title || t('brightness')}
91
+ {actionGroup?.title || item?.label || t('brightness')}
64
92
  </Text>
65
- </View>
66
- <View style={styles.RightBrightness}>
67
- <Slider
68
- containerStyle={styles.slider}
69
- value={valueBrightness}
70
- onSlidingComplete={onChangeBrightness}
71
- onValueChange={setValueBrightness}
72
- step={1}
73
- minimumValue={0}
74
- maximumValue={100}
75
- thumbTintColor={Colors.Gray3}
76
- minimumTrackTintColor={Colors.Primary}
77
- maximumTrackTintColor={Colors.Gray4}
78
- trackStyle={styles.trackSlider}
79
- thumbStyle={styles.thumbSlider}
80
- />
81
- <View style={styles.valuePercent}>
82
- <Text type="Label" style={styles.textValuePercent}>
83
- {`${valueBrightness}%`}
84
- </Text>
93
+
94
+ <View style={styles.wrap}>
95
+ <Slider
96
+ step={1}
97
+ minimumValue={min_value}
98
+ maximumValue={max_value}
99
+ value={valueBrightness < min_value ? min_value : valueBrightness}
100
+ onValueChange={onValueChange}
101
+ onSlidingComplete={onChangeBrightness}
102
+ minimumTrackTintColor={Colors.Primary}
103
+ maximumTrackTintColor={Colors.Gray3}
104
+ trackStyle={styles.trackSlider}
105
+ thumbStyle={styles.thumbSlider}
106
+ containerStyle={styles.slider}
107
+ />
108
+ <_TextInput
109
+ keyboardType="numeric"
110
+ style={styles.text}
111
+ wrapStyle={styles.wrapInputStyle}
112
+ textInputStyle={styles.textInputStyle}
113
+ value={getTextInputValue.toString()}
114
+ onChange={onInputChange}
115
+ />
85
116
  </View>
86
117
  </View>
87
- </View>
88
- );
89
- });
118
+ );
119
+ }
120
+ );
90
121
 
91
122
  export default SliderRangeTemplate;
@@ -6,44 +6,44 @@ export default StyleSheet.create({
6
6
  marginBottom: 16,
7
7
  marginHorizontal: 16,
8
8
  padding: 16,
9
- flexDirection: 'row',
10
- alignItems: 'center',
11
- justifyContent: 'space-around',
12
9
  borderWidth: 1,
13
10
  borderColor: Colors.Gray4,
14
11
  borderRadius: 10,
15
12
  },
16
- slider: {
17
- width: 131,
18
- },
19
13
  trackSlider: {
20
- height: 8,
21
- borderRadius: 30,
14
+ height: 4,
22
15
  },
23
16
  thumbSlider: {
24
- backgroundColor: Colors.Primary,
25
- width: 20,
26
- height: 20,
27
- },
28
- valuePercent: {
29
- width: 45,
30
- flexDirection: 'row',
31
- paddingLeft: 16,
17
+ backgroundColor: Colors.White,
18
+ borderColor: Colors.Primary,
19
+ borderWidth: 3,
32
20
  },
33
- textValuePercent: {
34
- width: 45,
35
- },
36
- LeftBrightness: {
37
- flex: 1,
21
+ wrap: {
38
22
  flexDirection: 'row',
39
23
  alignItems: 'center',
24
+ width: '100%',
25
+ flexWrap: 'nowrap',
40
26
  },
41
- LeftTextBrightness: {
42
- paddingTop: 4,
43
- paddingLeft: 8,
27
+ text: {
28
+ marginTop: 8,
44
29
  },
45
- RightBrightness: {
46
- flexDirection: 'row',
47
- alignItems: 'center',
30
+ slider: {
31
+ width: '77%',
32
+ },
33
+ wrapInputStyle: {
34
+ marginTop: 0,
35
+ width: '23%',
36
+ },
37
+ textInputStyle: {
38
+ marginTop: 0,
39
+ marginLeft: 10,
40
+ borderRadius: 4,
41
+ paddingTop: 5,
42
+ paddingBottom: 5,
43
+ paddingHorizontal: 20,
44
+
45
+ shadowColor: Colors.Gray13,
46
+ borderColor: Colors.Gray5,
47
+ borderWidth: 1,
48
48
  },
49
49
  });
@@ -38,6 +38,7 @@ const GridItem = ({ item, doAction, sensor }) => {
38
38
  } = item;
39
39
  const buttonOnOffStyle = active ? buttonStyle.ON : buttonStyle.OFF;
40
40
  const checkIcon = /\d/.test(icon); // to do check icon svg and icon antDesign
41
+
41
42
  const doActionAndWatchConfig = useCallback(
42
43
  (actionData) => {
43
44
  let data = null;
@@ -76,9 +77,10 @@ const GridItem = ({ item, doAction, sensor }) => {
76
77
  case 'air-dry-1':
77
78
  return <SvgAirDry width={24} height={24} />;
78
79
  default:
79
- return () => <></>;
80
+ return null;
80
81
  }
81
82
  }, [icon]);
83
+
82
84
  return (
83
85
  <View
84
86
  accessibilityLabel={AccessibilityLabel.STATES_GRID_ACTION_GRID_ITEM}
@@ -142,6 +144,7 @@ const StatesGridActionTemplate = ({
142
144
  >
143
145
  {options.map((item, index) => (
144
146
  <GridItem
147
+ key={index}
145
148
  item={item}
146
149
  index={index}
147
150
  doAction={doAction}
@@ -77,6 +77,7 @@ describe('Test OnOffTemplate', () => {
77
77
 
78
78
  beforeEach(() => {
79
79
  watchMultiConfigs.mockClear();
80
+ jest.useFakeTimers();
80
81
 
81
82
  actionGroup = {
82
83
  template: 'OnOffSimpleActionTemplate',
@@ -265,7 +266,9 @@ describe('Test OnOffTemplate', () => {
265
266
  await act(async () => {
266
267
  await template[0].props.triggerAction();
267
268
  });
268
- jest.runAllTimers();
269
+ await act(async () => {
270
+ jest.runAllTimers();
271
+ });
269
272
  expect(mockDoAction).toHaveBeenCalledWith(action_data, {
270
273
  value: 0,
271
274
  state: 0,
@@ -6,6 +6,7 @@ import { SCProvider } from '../../../context';
6
6
  import { mockSCStore } from '../../../context/mockStore';
7
7
  import { useConfigGlobalState } from '../../../iot/states';
8
8
  import { Slider } from '@miblanchard/react-native-slider';
9
+ import _TextInput from '../../Form/TextInput';
9
10
 
10
11
  jest.mock('../../../iot/Monitor');
11
12
  const mockDoAction = jest.fn();
@@ -36,6 +37,7 @@ describe('Test SliderRangeTemplate', () => {
36
37
  };
37
38
 
38
39
  beforeEach(() => {
40
+ jest.useFakeTimers();
39
41
  watchMultiConfigs.mockClear();
40
42
  mockDoAction.mockClear();
41
43
  actionGroup = {
@@ -83,4 +85,58 @@ describe('Test SliderRangeTemplate', () => {
83
85
  const silderRange = instance.findByType(Slider);
84
86
  expect(silderRange.props.value).toBe(50);
85
87
  });
88
+
89
+ it('test change input invalid number', async () => {
90
+ useConfigGlobalState.mockImplementation(() => [
91
+ {
92
+ 5: {
93
+ value: 50,
94
+ },
95
+ },
96
+ jest.fn(),
97
+ ]);
98
+ const sensor = { is_managed_by_backend: true, name: 'Sensor' };
99
+
100
+ await act(async () => {
101
+ wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
102
+ });
103
+ const instance = wrapper.root;
104
+ const textInput = instance.findByType(_TextInput);
105
+ expect(textInput.props.value).toEqual('50');
106
+
107
+ await act(async () => {
108
+ await textInput.props.onChange('aaaa');
109
+ });
110
+ expect(textInput.props.value).toEqual('50'); // not change value
111
+ });
112
+
113
+ it('test change input called doAction', async () => {
114
+ useConfigGlobalState.mockImplementation(() => [
115
+ {
116
+ 5: {
117
+ value: 50,
118
+ },
119
+ },
120
+ jest.fn(),
121
+ ]);
122
+ const sensor = { is_managed_by_backend: true, name: 'Sensor' };
123
+
124
+ await act(async () => {
125
+ wrapper = await create(wrapComponent(actionGroup, mockDoAction, sensor));
126
+ });
127
+
128
+ const instance = wrapper.root;
129
+ let textInput = instance.findByType(_TextInput);
130
+
131
+ await act(async () => {
132
+ await textInput.props.onChange('60');
133
+ });
134
+ await act(async () => {
135
+ jest.runAllTimers();
136
+ });
137
+ expect(mockDoAction).toHaveBeenCalledWith(
138
+ action_data,
139
+ JSON.stringify({ value_brness: 60, value: 60 })
140
+ );
141
+ });
86
142
  });
@@ -20,7 +20,7 @@ describe('Test StatesGridActionTemplate', () => {
20
20
  configuration: {
21
21
  options: [
22
22
  {
23
- config: true,
23
+ config: 1,
24
24
  active: false,
25
25
  text: 'item 1',
26
26
  icon_kit_data: 'icon_kit_data',
@@ -28,7 +28,7 @@ describe('Test StatesGridActionTemplate', () => {
28
28
  action_data: mockActionData,
29
29
  },
30
30
  {
31
- config: false,
31
+ config: 2,
32
32
  active: true,
33
33
  text: 'item 2',
34
34
  icon_kit_data: 'icon_kit_data',