@eohjsc/react-native-smart-city 0.4.89 → 0.4.91

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
  {
2
2
  "name": "@eohjsc/react-native-smart-city",
3
3
  "title": "React Native Smart Home",
4
- "version": "0.4.89",
4
+ "version": "0.4.91",
5
5
  "description": "TODO",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -10,12 +10,23 @@ import styles from './styles';
10
10
  const ProgressBar = memo(({ data = [], item, isWidgetOrder }) => {
11
11
  const t = useTranslations();
12
12
 
13
+ const minValue = useMemo(() => {
14
+ return Number(item?.configuration?.min_value) || 0;
15
+ }, [item?.configuration?.min_value]);
13
16
  const maxValue = useMemo(() => {
14
17
  return Number(item?.configuration?.max_value) || 60;
15
18
  }, [item?.configuration?.max_value]);
16
- const { value = 0, measure, unit } = data.length ? data[0] : {};
17
- const percent = value / maxValue; // a number between 0 and 1
19
+
20
+ let { value = 0, measure, unit } = data.length ? data[0] : {};
18
21
  const isNotValue = ['', null, undefined, NaN].includes(value);
22
+
23
+ if (isNotValue) {
24
+ value = minValue;
25
+ }
26
+
27
+ const distance = maxValue - minValue;
28
+ const percent = (value - minValue) / distance;
29
+
19
30
  return (
20
31
  <View style={(isWidgetOrder && styles.wrapOrderItem) || styles.container}>
21
32
  <Text size={16} style={styles.textLabel}>
@@ -1,19 +1,19 @@
1
1
  import React, { memo, useCallback, useMemo, useState } from 'react';
2
- import Svg, { Path, Text, Circle } from 'react-native-svg';
3
- import { View, StyleSheet, Text as ReactText } from 'react-native';
2
+ import { Text as ReactText, StyleSheet, View } from 'react-native';
3
+ import Svg, { Circle, Path, Text } from 'react-native-svg';
4
4
 
5
+ import { Colors, Fonts } from '../../../../configs';
6
+ import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
5
7
  import {
6
8
  drawArc,
7
9
  polarToCartesian,
8
10
  } from '../../../UnitSummary/AirQuality/SegmentedRoundDisplay/helper';
9
- import { Colors, Fonts } from '../../../../configs';
10
- import AccessibilityLabel from '../../../../configs/AccessibilityLabel';
11
11
 
12
12
  const { PI } = Math;
13
13
 
14
14
  const Anemometer = memo(
15
15
  ({
16
- data = [],
16
+ data = [{ value: 0 }],
17
17
  width = 240,
18
18
  size = 170,
19
19
  strokeWidth = 16,
@@ -29,11 +29,19 @@ const Anemometer = memo(
29
29
  y: size / 2,
30
30
  };
31
31
 
32
+ const minValue = useMemo(() => {
33
+ return Number(item?.configuration?.min_value) || 0;
34
+ }, [item?.configuration?.min_value]);
35
+
32
36
  const maxValue = useMemo(() => {
33
37
  return Number(item?.configuration?.max_value) || 60;
34
38
  }, [item?.configuration?.max_value]);
35
39
 
36
- const value = data.length && data[0]?.value ? data[0].value : 0;
40
+ const configValue = data.length && data[0]?.value;
41
+
42
+ const isValidValue = ![null, undefined, NaN].includes(configValue);
43
+ const value = isValidValue ? configValue : minValue;
44
+
37
45
  const measure = data.length ? data[0].unit || data[0].measure : 'm/s';
38
46
 
39
47
  const radius = (size - strokeWidth) / 2;
@@ -44,7 +52,10 @@ const Anemometer = memo(
44
52
  const strokeLength = (strokeAngle * circumference) / 360 - 1;
45
53
  const strokeDasharrayBg = `${strokeLength} 1`;
46
54
  const arc = circumference * 0.75;
47
- const offset = arc - (value / maxValue) * arc;
55
+
56
+ const total = minValue + maxValue;
57
+ const distance = maxValue - minValue;
58
+ const offset = arc - (((value || 0) - minValue) / distance) * arc;
48
59
 
49
60
  const textAngles = useCallback(() => {
50
61
  let arr = [];
@@ -67,7 +78,7 @@ const Anemometer = memo(
67
78
  fontFamily={Fonts.Regular}
68
79
  key={i.toString()}
69
80
  >
70
- {(i / numberOfSection) * maxValue}
81
+ {minValue}
71
82
  </Text>
72
83
  );
73
84
  }
@@ -88,7 +99,7 @@ const Anemometer = memo(
88
99
  textAnchor="middle"
89
100
  fontFamily={Fonts.Regular}
90
101
  >
91
- {(i / numberOfSection) * maxValue}
102
+ {0.5 * total}
92
103
  </Text>
93
104
  );
94
105
  }
@@ -116,13 +127,15 @@ const Anemometer = memo(
116
127
  }
117
128
  return arr;
118
129
  }, [
130
+ size,
119
131
  numberOfSection,
132
+ width,
120
133
  startAngle,
121
134
  strokeAngle,
122
- size,
123
- width,
124
- maxValue,
125
135
  txtColor,
136
+ minValue,
137
+ total,
138
+ maxValue,
126
139
  ]);
127
140
 
128
141
  // eslint-disable-next-line no-shadow
@@ -188,9 +201,11 @@ const Anemometer = memo(
188
201
  onPressOut={handleShowToolTip(false)}
189
202
  accessibilityLabel={AccessibilityLabel.GAUGE_VALUE}
190
203
  >
191
- {value.toString().length > 10
192
- ? value.toString().substring(0, 10) + '...'
193
- : value}
204
+ {isValidValue
205
+ ? value.toString().length > 10
206
+ ? value.toString().substring(0, 10) + '...'
207
+ : value
208
+ : '--'}
194
209
  </Text>
195
210
  </Svg>
196
211
  {isShowToolTip && (
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useMemo, useState } from 'react';
2
- import { View } from 'react-native';
2
+ import { Keyboard, TouchableWithoutFeedback, View } from 'react-native';
3
3
  import { useNavigation } from '@react-navigation/native';
4
4
  import styles from './Styles/SetupScriptDelayStyles';
5
5
  import { HeaderCustom } from '../../../commons';
@@ -55,25 +55,27 @@ const SetupScriptDelay = ({ route }) => {
55
55
  return (
56
56
  <View style={styles.wrap}>
57
57
  <HeaderCustom isShowClose onClose={goBack} title={t('wait')} />
58
- <View style={styles.container}>
59
- <_TextInput
60
- label={t('set_timeout_seconds')}
61
- placeholder={t('maximum_3600_seconds')}
62
- keyboardType="numeric"
63
- textInputStyle={styles.inputNumber}
64
- value={delay}
65
- onChange={onChangeTitle}
66
- maxLength={4}
67
- accessibilityLabel={AccessibilityLabel.AUTOMATE_INPUT_DELAY}
68
- autoFocus
69
- />
70
- <BottomButtonView
71
- style={styles.bottomButtonView}
72
- mainTitle={t('save')}
73
- onPressMain={onNext}
74
- typeMain={canSave ? 'primary' : 'disabled'}
75
- />
76
- </View>
58
+ <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
59
+ <View style={styles.container}>
60
+ <_TextInput
61
+ label={t('set_timeout_seconds')}
62
+ placeholder={t('maximum_3600_seconds')}
63
+ keyboardType="numeric"
64
+ textInputStyle={styles.inputNumber}
65
+ value={delay}
66
+ onChange={onChangeTitle}
67
+ maxLength={4}
68
+ accessibilityLabel={AccessibilityLabel.AUTOMATE_INPUT_DELAY}
69
+ autoFocus
70
+ />
71
+ <BottomButtonView
72
+ style={styles.bottomButtonView}
73
+ mainTitle={t('save')}
74
+ onPressMain={onNext}
75
+ typeMain={canSave ? 'primary' : 'disabled'}
76
+ />
77
+ </View>
78
+ </TouchableWithoutFeedback>
77
79
  </View>
78
80
  );
79
81
  };
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useMemo, useState } from 'react';
2
- import { View } from 'react-native';
2
+ import { Keyboard, TouchableWithoutFeedback, View } from 'react-native';
3
3
  import { useNavigation } from '@react-navigation/native';
4
4
  import styles from './Styles/SetupScriptNotifyStyles';
5
5
  import { HeaderCustom } from '../../../commons';
@@ -59,32 +59,33 @@ const SetupScriptNotify = ({ route }) => {
59
59
  return (
60
60
  <View style={styles.wrap}>
61
61
  <HeaderCustom isShowClose onClose={goBack} title={t('notification')} />
62
- <View style={styles.container}>
63
- <_TextInput
64
- placeholder={t('title_notification')}
65
- onChange={onChangeTitle}
66
- textInputStyle={styles.textTitle}
67
- value={notify?.title}
68
- accessibilityLabel={AccessibilityLabel.AUTOMATE_TITLE_NOTIFY}
69
- autoFocus
70
- />
71
- <_TextInput
72
- placeholder={t('message_notification')}
73
- onChange={onChangeMessage}
74
- textInputStyle={styles.textMessage}
75
- value={notify?.message}
76
- accessibilityLabel={AccessibilityLabel.AUTOMATE_MESSAGE_NOTIFY}
77
- multiline={true}
78
- maxLength={255}
79
- />
80
-
81
- <BottomButtonView
82
- style={styles.bottomButtonView}
83
- mainTitle={t('save')}
84
- onPressMain={onNext}
85
- typeMain={canSave ? 'primary' : 'disabled'}
86
- />
87
- </View>
62
+ <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
63
+ <View style={styles.container}>
64
+ <_TextInput
65
+ placeholder={t('title_notification')}
66
+ onChange={onChangeTitle}
67
+ textInputStyle={styles.textTitle}
68
+ value={notify?.title}
69
+ accessibilityLabel={AccessibilityLabel.AUTOMATE_TITLE_NOTIFY}
70
+ autoFocus
71
+ />
72
+ <_TextInput
73
+ placeholder={t('message_notification')}
74
+ onChange={onChangeMessage}
75
+ textInputStyle={styles.textMessage}
76
+ value={notify?.message}
77
+ accessibilityLabel={AccessibilityLabel.AUTOMATE_MESSAGE_NOTIFY}
78
+ multiline={true}
79
+ maxLength={255}
80
+ />
81
+ <BottomButtonView
82
+ style={styles.bottomButtonView}
83
+ mainTitle={t('save')}
84
+ onPressMain={onNext}
85
+ typeMain={canSave ? 'primary' : 'disabled'}
86
+ />
87
+ </View>
88
+ </TouchableWithoutFeedback>
88
89
  </View>
89
90
  );
90
91
  };
@@ -21,6 +21,7 @@ export default StyleSheet.create({
21
21
  },
22
22
  textMessage: {
23
23
  height: 500,
24
+ textAlignVertical: 'top',
24
25
  borderWidth: 1,
25
26
  borderColor: Colors.Gray4,
26
27
  borderStyle: 'solid',
@@ -11,6 +11,7 @@ import _TextInput from '../../../../commons/Form/TextInput';
11
11
  import BottomButtonView from '../../../../commons/BottomButtonView';
12
12
  import { ToastBottomHelper } from '../../../../utils/Utils';
13
13
  import SetupScriptDelay from '../SetupScriptDelay';
14
+ import { TouchableWithoutFeedback } from 'react-native';
14
15
 
15
16
  const mock = new MockAdapter(api.axiosInstance);
16
17
 
@@ -55,6 +56,10 @@ describe('Test SetupScriptDelay', () => {
55
56
  inputs[0].props.onChange('u');
56
57
  });
57
58
  expect(button.props.typeMain).toEqual('disabled');
59
+ const touchable = instance.findAllByType(TouchableWithoutFeedback);
60
+ await act(async () => {
61
+ touchable[0].props.onPress();
62
+ });
58
63
  await act(async () => {
59
64
  inputs[0].props.onChange('0');
60
65
  });
@@ -11,6 +11,7 @@ import SetupScriptNotify from '../SetupScriptNotify';
11
11
  import _TextInput from '../../../../commons/Form/TextInput';
12
12
  import BottomButtonView from '../../../../commons/BottomButtonView';
13
13
  import { ToastBottomHelper } from '../../../../utils/Utils';
14
+ import { TouchableWithoutFeedback } from 'react-native';
14
15
 
15
16
  const mock = new MockAdapter(api.axiosInstance);
16
17
 
@@ -53,6 +54,12 @@ describe('Test SetupScriptNotify', () => {
53
54
 
54
55
  await act(async () => {
55
56
  inputs[0].props.onChange('Title');
57
+ });
58
+ const touchable = instance.findAllByType(TouchableWithoutFeedback);
59
+ await act(async () => {
60
+ touchable[0].props.onPress();
61
+ });
62
+ await act(async () => {
56
63
  inputs[1].props.onChange('Message');
57
64
  });
58
65
  const button = instance.findByType(BottomButtonView);
@@ -218,12 +218,14 @@ const ScriptDetail = ({ route }) => {
218
218
  onGoBack={goBack}
219
219
  >
220
220
  <View style={styles.wrapContent}>
221
- <View style={styles.row}>
222
- <Text type="H3" semibold>
223
- {t('enable_this_script')}
224
- </Text>
225
- <Switch checked={enableScript} onChange={onChangeSwitch} />
226
- </View>
221
+ {!!can_edit && !!enableScript && (
222
+ <View style={styles.row}>
223
+ <Text type="H3" semibold>
224
+ {t('enable_this_script')}
225
+ </Text>
226
+ <Switch checked={enableScript} onChange={onChangeSwitch} />
227
+ </View>
228
+ )}
227
229
  <Text type="H3" semibold>
228
230
  {t('how_to_start')}
229
231
  </Text>
@@ -1,26 +1,26 @@
1
1
  import React, { useCallback, useState } from 'react';
2
2
  import { View } from 'react-native';
3
3
  import ActionGroup from '../../../commons/ActionGroup';
4
- import { AccessibilityLabel } from '../../../configs/Constants';
5
- import { DetailHistoryChart } from './DetailHistoryChart';
6
- import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
7
- import PMSensorIndicator from '../../../commons/Device/PMSensor/PMSensorIndicator';
8
- import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
9
- import styles from '../styles';
10
- import Compass from '../../../commons/Device/WindDirection/Compass';
11
4
  import DeviceAlertStatus from '../../../commons/Device/DeviceAlertStatus';
12
- import FlatListItems from '../../../commons/Device/FlatListItems';
13
- import ListQualityIndicator from '../../../commons/Device/WaterQualitySensor/ListQualityIndicator';
14
- import EmergencyDetail from '../../../commons/Device/Emergency/EmergencyDetail';
15
5
  import EmergencyButton from '../../../commons/Device/Emergency/EmergencyButton';
6
+ import EmergencyDetail from '../../../commons/Device/Emergency/EmergencyDetail';
7
+ import FlatListItems from '../../../commons/Device/FlatListItems';
16
8
  import FooterInfo from '../../../commons/Device/FooterInfo';
9
+ import PMSensorIndicator from '../../../commons/Device/PMSensor/PMSensorIndicator';
10
+ import ProgressBar from '../../../commons/Device/ProgressBar';
11
+ import CurrentRainSensor from '../../../commons/Device/RainningSensor/CurrentRainSensor';
12
+ import ListQualityIndicator from '../../../commons/Device/WaterQualitySensor/ListQualityIndicator';
13
+ import Compass from '../../../commons/Device/WindDirection/Compass';
14
+ import Anemometer from '../../../commons/Device/WindSpeed/Anemometer';
17
15
  import MediaPlayerDetail from '../../../commons/MediaPlayerDetail';
18
- import SmartIr from '../../../screens/SmartIr';
16
+ import { AccessibilityLabel } from '../../../configs/Constants';
19
17
  import { useSCContextSelector } from '../../../context';
20
18
  import { useRemoteControl } from '../../../hooks/IoT';
21
19
  import { useConfigGlobalState } from '../../../iot/states';
20
+ import SmartIr from '../../../screens/SmartIr';
22
21
  import { useEvaluateValue } from '../hooks/useEvaluateValue';
23
- import ProgressBar from '../../../commons/Device/ProgressBar';
22
+ import styles from '../styles';
23
+ import { DetailHistoryChart } from './DetailHistoryChart';
24
24
  import VisualChart from './VisualChart';
25
25
 
26
26
  export const SensorDisplayItem = ({