@controleonline/ui-common 1.2.130 → 1.2.131
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/.release/rc-manifest.json +5 -5
- package/package.json +1 -1
- package/src/react/components/RuntimeFooterMarqueeText.js +107 -6
- package/src/react/components/RuntimeInfoFooter.js +10 -48
- package/src/react/utils/runtimeFooter.js +2 -0
- package/src/react/utils/runtimeFooterText.js +11 -0
- package/src/tests/react/components/RuntimeFooterMarqueeText.test.js +140 -0
- package/src/tests/react/utils/runtimeFooterText.test.js +34 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.131",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.2.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.2.131-rc.1",
|
|
5
|
+
"baseMaster": "3aeaced0835b88b82621be16259985080203eee1",
|
|
6
6
|
"tasks": [
|
|
7
|
-
|
|
7
|
+
159
|
|
8
8
|
],
|
|
9
9
|
"frozen": true,
|
|
10
10
|
"repositories": {
|
|
11
|
-
"ControleOnline/ui-common": "
|
|
11
|
+
"ControleOnline/ui-common": "96efe92a8b5fd573c7688b21713f75fe7a0b57c2"
|
|
12
12
|
}
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ const React = require('react');
|
|
|
2
2
|
const {useEffect, useRef, useState} = React;
|
|
3
3
|
const RN = require('react-native');
|
|
4
4
|
const Animated = RN.Animated;
|
|
5
|
+
const Easing = RN.Easing;
|
|
5
6
|
const Text = RN.Text;
|
|
6
7
|
const View = RN.View;
|
|
7
8
|
const Platform = RN.Platform || {OS: 'native'};
|
|
@@ -12,10 +13,22 @@ const GAP_PX = 32;
|
|
|
12
13
|
const MS_PER_PX = 28;
|
|
13
14
|
const MIN_DURATION_MS = 4000;
|
|
14
15
|
const HOLD_MS = 1200;
|
|
16
|
+
// Continuous ticker (right -> left): constant, readable speed.
|
|
17
|
+
const TICKER_MS_PER_PX = 20;
|
|
18
|
+
const TICKER_MIN_DURATION_MS = 3000;
|
|
19
|
+
// Native Text is measured with the parent width as the maximum, so a row as
|
|
20
|
+
// narrow as the container would truncate the text (and the measured content
|
|
21
|
+
// width). The ticker row is therefore much wider than any footer; the
|
|
22
|
+
// container clips it (overflow: hidden).
|
|
23
|
+
const TICKER_ROW_WIDTH_PX = 20000;
|
|
15
24
|
|
|
16
25
|
/**
|
|
17
26
|
* Single-line footer text. When content overflows the available width,
|
|
18
27
|
* scrolls horizontally in a continuous loop. Short text stays static.
|
|
28
|
+
*
|
|
29
|
+
* `continuous` turns it into a ticker (marquee): the text ALWAYS scrolls from
|
|
30
|
+
* right to left in a seamless loop (repeated copies fill the width), on web
|
|
31
|
+
* (CSS keyframes) and native (Animated loop with the native driver).
|
|
19
32
|
* On web, avoids Animated opacity/transform issues that hid the label.
|
|
20
33
|
* RN Web also needs intrinsic sizing because Text can collapse to width 0
|
|
21
34
|
* inside a flex row.
|
|
@@ -28,6 +41,7 @@ const RuntimeFooterMarqueeText = props => {
|
|
|
28
41
|
const text = props && props.text;
|
|
29
42
|
const color = props && props.color;
|
|
30
43
|
const style = props && props.style;
|
|
44
|
+
const continuous = !!(props && props.continuous);
|
|
31
45
|
const testID =
|
|
32
46
|
(props && props.testID) || 'runtime-footer-marquee-text';
|
|
33
47
|
|
|
@@ -36,8 +50,9 @@ const RuntimeFooterMarqueeText = props => {
|
|
|
36
50
|
const translateX = useRef(new Animated.Value(0)).current;
|
|
37
51
|
const animationRef = useRef(null);
|
|
38
52
|
|
|
39
|
-
const shouldMarquee =
|
|
40
|
-
|
|
53
|
+
const shouldMarquee = continuous
|
|
54
|
+
? containerWidth > 0 && contentWidth > 0
|
|
55
|
+
: !IS_WEB && containerWidth > 0 && contentWidth > containerWidth + 2;
|
|
41
56
|
|
|
42
57
|
useEffect(() => {
|
|
43
58
|
if (animationRef.current) {
|
|
@@ -47,18 +62,22 @@ const RuntimeFooterMarqueeText = props => {
|
|
|
47
62
|
translateX.stopAnimation();
|
|
48
63
|
translateX.setValue(0);
|
|
49
64
|
|
|
50
|
-
|
|
65
|
+
// On web the continuous ticker uses CSS keyframes (see render below).
|
|
66
|
+
if (!shouldMarquee || (continuous && IS_WEB)) {
|
|
51
67
|
return undefined;
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
const distance = contentWidth + GAP_PX;
|
|
55
|
-
const duration =
|
|
71
|
+
const duration = continuous
|
|
72
|
+
? Math.max(Math.round(distance * TICKER_MS_PER_PX), TICKER_MIN_DURATION_MS)
|
|
73
|
+
: Math.max(Math.round(distance * MS_PER_PX), MIN_DURATION_MS);
|
|
56
74
|
const loop = Animated.loop(
|
|
57
75
|
Animated.sequence([
|
|
58
|
-
Animated.delay(HOLD_MS),
|
|
76
|
+
Animated.delay(continuous ? 0 : HOLD_MS),
|
|
59
77
|
Animated.timing(translateX, {
|
|
60
78
|
toValue: -distance,
|
|
61
79
|
duration: duration,
|
|
80
|
+
easing: continuous && Easing ? Easing.linear : undefined,
|
|
62
81
|
useNativeDriver: USE_NATIVE_DRIVER,
|
|
63
82
|
}),
|
|
64
83
|
Animated.timing(translateX, {
|
|
@@ -75,7 +94,7 @@ const RuntimeFooterMarqueeText = props => {
|
|
|
75
94
|
animationRef.current = null;
|
|
76
95
|
translateX.stopAnimation();
|
|
77
96
|
};
|
|
78
|
-
}, [shouldMarquee, contentWidth, containerWidth, text, translateX]);
|
|
97
|
+
}, [shouldMarquee, continuous, contentWidth, containerWidth, text, translateX]);
|
|
79
98
|
|
|
80
99
|
const handleContainerLayout = event => {
|
|
81
100
|
const nextWidth = Math.round(
|
|
@@ -128,6 +147,88 @@ const RuntimeFooterMarqueeText = props => {
|
|
|
128
147
|
|
|
129
148
|
textStyle.push(shouldMarquee ? {textAlign: 'left'} : {textAlign: 'center'});
|
|
130
149
|
|
|
150
|
+
if (continuous) {
|
|
151
|
+
// Enough copies so the row is always wider than the container + one cycle:
|
|
152
|
+
// the loop restarts (translateX 0) with no visible gap.
|
|
153
|
+
const distance = contentWidth + GAP_PX;
|
|
154
|
+
const copies = shouldMarquee
|
|
155
|
+
? Math.max(2, Math.ceil(containerWidth / distance) + 1)
|
|
156
|
+
: 1;
|
|
157
|
+
const durationMs = Math.max(
|
|
158
|
+
Math.round(distance * TICKER_MS_PER_PX),
|
|
159
|
+
TICKER_MIN_DURATION_MS,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const copyNodes = [];
|
|
163
|
+
for (let index = 0; index < copies; index += 1) {
|
|
164
|
+
copyNodes.push(
|
|
165
|
+
React.createElement(
|
|
166
|
+
Text,
|
|
167
|
+
{
|
|
168
|
+
key: 'ticker-copy-' + index,
|
|
169
|
+
numberOfLines: 1,
|
|
170
|
+
ellipsizeMode: 'clip',
|
|
171
|
+
accessible: index === 0,
|
|
172
|
+
importantForAccessibility: index === 0 ? 'auto' : 'no',
|
|
173
|
+
onLayout: index === 0 ? handleTextLayout : undefined,
|
|
174
|
+
testID: index === 0 ? undefined : 'runtime-footer-ticker-copy',
|
|
175
|
+
style: textStyle.concat([
|
|
176
|
+
{textAlign: 'left', marginRight: GAP_PX},
|
|
177
|
+
IS_WEB ? {whiteSpace: 'nowrap'} : null,
|
|
178
|
+
]),
|
|
179
|
+
},
|
|
180
|
+
text,
|
|
181
|
+
),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const rowStyle = {
|
|
186
|
+
flexDirection: 'row',
|
|
187
|
+
flexWrap: 'nowrap',
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
alignSelf: 'flex-start',
|
|
190
|
+
opacity: 1,
|
|
191
|
+
};
|
|
192
|
+
if (!IS_WEB) {
|
|
193
|
+
rowStyle.width = TICKER_ROW_WIDTH_PX;
|
|
194
|
+
}
|
|
195
|
+
if (IS_WEB && shouldMarquee) {
|
|
196
|
+
rowStyle.animationKeyframes = [
|
|
197
|
+
{
|
|
198
|
+
'0%': {transform: [{translateX: 0}]},
|
|
199
|
+
'100%': {transform: [{translateX: -distance}]},
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
rowStyle.animationDuration = durationMs + 'ms';
|
|
203
|
+
rowStyle.animationIterationCount = 'infinite';
|
|
204
|
+
rowStyle.animationTimingFunction = 'linear';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return React.createElement(
|
|
208
|
+
View,
|
|
209
|
+
{
|
|
210
|
+
testID: testID,
|
|
211
|
+
style: {
|
|
212
|
+
flex: 1,
|
|
213
|
+
overflow: 'hidden',
|
|
214
|
+
justifyContent: 'center',
|
|
215
|
+
opacity: 1,
|
|
216
|
+
},
|
|
217
|
+
onLayout: handleContainerLayout,
|
|
218
|
+
},
|
|
219
|
+
React.createElement(
|
|
220
|
+
IS_WEB ? View : Animated.View,
|
|
221
|
+
{
|
|
222
|
+
testID: 'runtime-footer-ticker-row',
|
|
223
|
+
style: IS_WEB
|
|
224
|
+
? rowStyle
|
|
225
|
+
: [rowStyle, {transform: [{translateX: translateX}]}],
|
|
226
|
+
},
|
|
227
|
+
copyNodes,
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
131
232
|
const content = React.createElement(
|
|
132
233
|
Text,
|
|
133
234
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {useMemo} from 'react';
|
|
2
2
|
import {
|
|
3
3
|
ActivityIndicator,
|
|
4
4
|
Platform,
|
|
@@ -18,14 +18,13 @@ import {
|
|
|
18
18
|
getRuntimeFooterDebugInfo,
|
|
19
19
|
getRuntimeFooterPrimaryText,
|
|
20
20
|
getRuntimeFooterRotationEntries,
|
|
21
|
+
getRuntimeFooterTickerText,
|
|
21
22
|
getRuntimeFooterText,
|
|
22
|
-
getRuntimeFooterTextLines,
|
|
23
23
|
} from '@controleonline/ui-common/src/react/utils/runtimeFooter';
|
|
24
24
|
import styles from './RuntimeInfoFooter.styles';
|
|
25
25
|
import RuntimeFooterMarqueeText from './RuntimeFooterMarqueeText';
|
|
26
26
|
import resolveHomeFooterSpacing from './RuntimeInfoFooter.home.spacing';
|
|
27
27
|
|
|
28
|
-
const ROTATION_INTERVAL_MS = 4000;
|
|
29
28
|
const COMPACT_BREAKPOINT = 720;
|
|
30
29
|
const MAX_INLINE_TEXT_LENGTH = 84;
|
|
31
30
|
const FALLBACK_TEXT_COLOR = '#0f172a';
|
|
@@ -72,7 +71,6 @@ const RuntimeInfoFooter = ({
|
|
|
72
71
|
}) => {
|
|
73
72
|
const {width} = useWindowDimensions();
|
|
74
73
|
const insets = useSafeAreaInsets();
|
|
75
|
-
const [activeIndex, setActiveIndex] = useState(0);
|
|
76
74
|
const allStores = useStores(state => state);
|
|
77
75
|
const deviceConfigStore = useStore('device_config');
|
|
78
76
|
const runtimeDebugStore = useStore('runtime_debug');
|
|
@@ -119,10 +117,6 @@ const RuntimeInfoFooter = ({
|
|
|
119
117
|
deviceConfigItem?.configs,
|
|
120
118
|
storeMainCompany?.configs,
|
|
121
119
|
]);
|
|
122
|
-
const footerTextLines = useMemo(
|
|
123
|
-
() => getRuntimeFooterTextLines(companyFooterText),
|
|
124
|
-
[companyFooterText],
|
|
125
|
-
);
|
|
126
120
|
const deviceConfigs = useMemo(
|
|
127
121
|
() => parseConfigsObject(deviceConfigItem?.configs),
|
|
128
122
|
[deviceConfigItem?.configs],
|
|
@@ -143,14 +137,13 @@ const RuntimeInfoFooter = ({
|
|
|
143
137
|
}),
|
|
144
138
|
[companyFooterText, primaryText],
|
|
145
139
|
);
|
|
140
|
+
// Ticker: the text written by the user (company footer) comes first, then the
|
|
141
|
+
// system text (e.g. "web • MANAGER (ip) / v1.10.x"). Both scroll together,
|
|
142
|
+
// right to left, in a continuous loop (no more alternating between them).
|
|
146
143
|
const inlineText = useMemo(
|
|
147
|
-
() =>
|
|
148
|
-
[
|
|
144
|
+
() => getRuntimeFooterTickerText({companyFooterText, primaryText}),
|
|
145
|
+
[companyFooterText, primaryText],
|
|
149
146
|
);
|
|
150
|
-
// Always rotate when there is more than one entry (e.g. 1 footer line + primaryText).
|
|
151
|
-
// Do not fall back to concatenated inlineText in that case.
|
|
152
|
-
const shouldRotate =
|
|
153
|
-
!showDebugInfo && rotationEntries.length > 1;
|
|
154
147
|
const footerEntries = useMemo(
|
|
155
148
|
() =>
|
|
156
149
|
Object.values(runtimeDebugSummary?.entries || {})
|
|
@@ -222,44 +215,12 @@ const RuntimeInfoFooter = ({
|
|
|
222
215
|
? 0
|
|
223
216
|
: Math.max(Number(insets.bottom) || 0, 16);
|
|
224
217
|
|
|
225
|
-
useEffect(() => {
|
|
226
|
-
if (!shouldRotate || rotationEntries.length <= 1) {
|
|
227
|
-
setActiveIndex(0);
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
let timeoutId;
|
|
232
|
-
let cancelled = false;
|
|
233
|
-
|
|
234
|
-
const scheduleTransition = () => {
|
|
235
|
-
timeoutId = setTimeout(() => {
|
|
236
|
-
if (cancelled) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
setActiveIndex(current => (current + 1) % rotationEntries.length);
|
|
240
|
-
scheduleTransition();
|
|
241
|
-
}, ROTATION_INTERVAL_MS);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
scheduleTransition();
|
|
245
|
-
|
|
246
|
-
return () => {
|
|
247
|
-
cancelled = true;
|
|
248
|
-
if (timeoutId) {
|
|
249
|
-
clearTimeout(timeoutId);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
}, [rotationEntries.length, shouldRotate]);
|
|
253
|
-
|
|
254
218
|
if (rotationEntries.length === 0 && !showDebugInfo) {
|
|
255
219
|
return null;
|
|
256
220
|
}
|
|
257
221
|
|
|
258
|
-
const displayedText =
|
|
259
|
-
|
|
260
|
-
? rotationEntries[activeIndex]
|
|
261
|
-
: inlineText
|
|
262
|
-
) || primaryText || formatRuntimeFooterIdentifier(device?.id) || '';
|
|
222
|
+
const displayedText =
|
|
223
|
+
inlineText || primaryText || formatRuntimeFooterIdentifier(device?.id) || '';
|
|
263
224
|
const backgroundColor = colors?.footerBackground;
|
|
264
225
|
const homeSpacing = resolveHomeFooterSpacing(appearance, Platform.OS, insets.bottom);
|
|
265
226
|
const borderColor = colors?.footerBorder;
|
|
@@ -305,6 +266,7 @@ const RuntimeInfoFooter = ({
|
|
|
305
266
|
}
|
|
306
267
|
color={textColor}
|
|
307
268
|
opacity={1}
|
|
269
|
+
continuous
|
|
308
270
|
style={styles.primaryText}
|
|
309
271
|
testID="runtime-footer-primary-text"
|
|
310
272
|
/>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const {
|
|
2
2
|
DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
|
|
3
3
|
getRuntimeFooterRotationEntries,
|
|
4
|
+
getRuntimeFooterTickerText,
|
|
4
5
|
getRuntimeFooterText,
|
|
5
6
|
getRuntimeFooterTextLines,
|
|
6
7
|
normalizeRuntimeFooterText,
|
|
@@ -482,6 +483,7 @@ module.exports = {
|
|
|
482
483
|
getRuntimeFooterNativeIdentifierCandidates,
|
|
483
484
|
getRuntimeFooterPrimaryText,
|
|
484
485
|
getRuntimeFooterRotationEntries,
|
|
486
|
+
getRuntimeFooterTickerText,
|
|
485
487
|
getRuntimeFooterStoredVersion,
|
|
486
488
|
getRuntimeFooterTextLines,
|
|
487
489
|
getRuntimeFooterVersionCandidates,
|
|
@@ -148,8 +148,19 @@ const getRuntimeFooterRotationEntries = ({companyFooterText, primaryText}) =>
|
|
|
148
148
|
Boolean,
|
|
149
149
|
);
|
|
150
150
|
|
|
151
|
+
const RUNTIME_FOOTER_TICKER_SEPARATOR = ' • ';
|
|
152
|
+
|
|
153
|
+
// Text of the footer ticker: the text written by the user (company footer)
|
|
154
|
+
// first, then the system text (e.g. "web • MANAGER (ip) / v1.10.x").
|
|
155
|
+
const getRuntimeFooterTickerText = ({companyFooterText, primaryText}) =>
|
|
156
|
+
getRuntimeFooterRotationEntries({companyFooterText, primaryText}).join(
|
|
157
|
+
RUNTIME_FOOTER_TICKER_SEPARATOR,
|
|
158
|
+
);
|
|
159
|
+
|
|
151
160
|
module.exports = {
|
|
152
161
|
DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
|
|
162
|
+
RUNTIME_FOOTER_TICKER_SEPARATOR,
|
|
163
|
+
getRuntimeFooterTickerText,
|
|
153
164
|
getRuntimeFooterRotationEntries,
|
|
154
165
|
getRuntimeFooterText,
|
|
155
166
|
getRuntimeFooterTextLines,
|
|
@@ -7,6 +7,7 @@ const React = require('react');
|
|
|
7
7
|
const originalLoad = Module._load;
|
|
8
8
|
let lastLoopConfig = null;
|
|
9
9
|
let animationStarts = 0;
|
|
10
|
+
let mockPlatformOS = 'android';
|
|
10
11
|
|
|
11
12
|
before(() => {
|
|
12
13
|
Module._load = function mockLoad(request, parent, isMain) {
|
|
@@ -63,6 +64,8 @@ before(() => {
|
|
|
63
64
|
},
|
|
64
65
|
Text: props => React.createElement('Text', props, props.children),
|
|
65
66
|
View: props => React.createElement('View', props, props.children),
|
|
67
|
+
Easing: {linear: 'linear'},
|
|
68
|
+
Platform: {OS: mockPlatformOS},
|
|
66
69
|
StyleSheet: {create: styles => styles},
|
|
67
70
|
};
|
|
68
71
|
}
|
|
@@ -193,3 +196,140 @@ test('native text keeps intrinsic width even when style carries flex: 1 (android
|
|
|
193
196
|
assert.equal(flat.flexGrow, 0);
|
|
194
197
|
assert.equal(flat.flexShrink, 0);
|
|
195
198
|
});
|
|
199
|
+
|
|
200
|
+
const TICKER_TEXT =
|
|
201
|
+
'www.controleonline.com \u2022 (11) 5555-5159 (Comercial) \u2022 web \u2022 MANAGER (179.125.133.217) / v1.10.236';
|
|
202
|
+
|
|
203
|
+
const renderTicker = ({containerWidth, contentWidth, text = TICKER_TEXT}) => {
|
|
204
|
+
const RuntimeFooterMarqueeText = loadComponent();
|
|
205
|
+
const renderer = require('react-test-renderer');
|
|
206
|
+
|
|
207
|
+
animationStarts = 0;
|
|
208
|
+
lastLoopConfig = null;
|
|
209
|
+
|
|
210
|
+
let tree;
|
|
211
|
+
renderer.act(() => {
|
|
212
|
+
tree = renderer.create(
|
|
213
|
+
React.createElement(RuntimeFooterMarqueeText, {
|
|
214
|
+
text,
|
|
215
|
+
color: '#111',
|
|
216
|
+
continuous: true,
|
|
217
|
+
style: {fontSize: 10},
|
|
218
|
+
}),
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
if (containerWidth) {
|
|
223
|
+
const root = tree.root.findByProps({testID: 'runtime-footer-marquee-text'});
|
|
224
|
+
renderer.act(() => {
|
|
225
|
+
root.props.onLayout({
|
|
226
|
+
nativeEvent: {layout: {width: containerWidth, height: 12}},
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
if (contentWidth) {
|
|
231
|
+
const firstText = tree.root.findAllByType('Text')[0];
|
|
232
|
+
renderer.act(() => {
|
|
233
|
+
firstText.props.onLayout({
|
|
234
|
+
nativeEvent: {layout: {width: contentWidth, height: 12}},
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return tree;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
describe('continuous ticker (right to left, loop)', () => {
|
|
242
|
+
test('native: scrolls even when the text fits, right to left, linear, no hold', () => {
|
|
243
|
+
mockPlatformOS = 'android';
|
|
244
|
+
// content (200) fits inside the container (800): a ticker must still scroll.
|
|
245
|
+
const tree = renderTicker({containerWidth: 800, contentWidth: 200});
|
|
246
|
+
|
|
247
|
+
assert.ok(lastLoopConfig, 'Animated.loop should start for a ticker');
|
|
248
|
+
const [hold, move, reset] = lastLoopConfig.items;
|
|
249
|
+
assert.equal(hold.ms, 0, 'ticker has no hold before moving');
|
|
250
|
+
assert.equal(move.config.toValue, -(200 + 32), 'moves left by one text cycle');
|
|
251
|
+
assert.equal(move.config.easing, 'linear');
|
|
252
|
+
assert.ok(move.config.toValue < 0, 'right to left');
|
|
253
|
+
assert.equal(reset.config.duration, 0, 'instant reset = seamless loop');
|
|
254
|
+
|
|
255
|
+
// The row must be wider than the container, otherwise native Text is
|
|
256
|
+
// measured with the container width as maximum and the text is truncated.
|
|
257
|
+
const row = tree.root.findByProps({testID: 'runtime-footer-ticker-row'});
|
|
258
|
+
const rowStyle = Object.assign({}, ...[].concat(row.props.style));
|
|
259
|
+
assert.ok(rowStyle.width >= 10000, 'ticker row must not be as narrow as the container');
|
|
260
|
+
assert.equal(rowStyle.flexWrap, 'nowrap');
|
|
261
|
+
|
|
262
|
+
// enough copies to always fill the width: ceil(800 / 232) + 1 = 5
|
|
263
|
+
const texts = tree.root.findAllByType('Text');
|
|
264
|
+
assert.equal(texts.length, 5);
|
|
265
|
+
texts.forEach(node => assert.equal(node.props.children, TICKER_TEXT));
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test('native: speed is constant (duration proportional to the distance)', () => {
|
|
269
|
+
mockPlatformOS = 'android';
|
|
270
|
+
renderTicker({containerWidth: 800, contentWidth: 200});
|
|
271
|
+
const shortDuration = lastLoopConfig.items[1].config.duration;
|
|
272
|
+
renderTicker({containerWidth: 800, contentWidth: 1000});
|
|
273
|
+
const longDuration = lastLoopConfig.items[1].config.duration;
|
|
274
|
+
|
|
275
|
+
assert.ok(shortDuration >= 3000);
|
|
276
|
+
assert.ok(longDuration > shortDuration);
|
|
277
|
+
assert.equal(Math.round(longDuration / (1000 + 32)), 20);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('native: before measuring there is a single copy and no animation', () => {
|
|
281
|
+
mockPlatformOS = 'android';
|
|
282
|
+
const tree = renderTicker({});
|
|
283
|
+
assert.equal(tree.root.findAllByType('Text').length, 1);
|
|
284
|
+
assert.equal(lastLoopConfig, null);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('native: a long text still scrolls with at least two copies', () => {
|
|
288
|
+
mockPlatformOS = 'android';
|
|
289
|
+
const tree = renderTicker({containerWidth: 300, contentWidth: 1500});
|
|
290
|
+
assert.equal(tree.root.findAllByType('Text').length, 2);
|
|
291
|
+
assert.equal(lastLoopConfig.items[1].config.toValue, -(1500 + 32));
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('web: uses CSS keyframes (right to left, infinite, linear), not Animated', () => {
|
|
295
|
+
mockPlatformOS = 'web';
|
|
296
|
+
const tree = renderTicker({containerWidth: 800, contentWidth: 200});
|
|
297
|
+
|
|
298
|
+
assert.equal(lastLoopConfig, null, 'web must not use Animated.loop');
|
|
299
|
+
const row = tree.root.findByProps({testID: 'runtime-footer-ticker-row'});
|
|
300
|
+
const style = Object.assign({}, ...[].concat(row.props.style));
|
|
301
|
+
assert.equal(style.animationIterationCount, 'infinite');
|
|
302
|
+
assert.equal(style.animationTimingFunction, 'linear');
|
|
303
|
+
assert.match(style.animationDuration, /^\d+ms$/);
|
|
304
|
+
const [keyframes] = style.animationKeyframes;
|
|
305
|
+
assert.equal(keyframes['0%'].transform[0].translateX, 0);
|
|
306
|
+
assert.equal(keyframes['100%'].transform[0].translateX, -(200 + 32));
|
|
307
|
+
assert.equal(tree.root.findAllByType('Text').length, 5);
|
|
308
|
+
mockPlatformOS = 'android';
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test('without the continuous prop the previous behaviour is kept', () => {
|
|
312
|
+
mockPlatformOS = 'android';
|
|
313
|
+
const RuntimeFooterMarqueeText = loadComponent();
|
|
314
|
+
const renderer = require('react-test-renderer');
|
|
315
|
+
animationStarts = 0;
|
|
316
|
+
lastLoopConfig = null;
|
|
317
|
+
let tree;
|
|
318
|
+
renderer.act(() => {
|
|
319
|
+
tree = renderer.create(
|
|
320
|
+
React.createElement(RuntimeFooterMarqueeText, {text: 'short', color: '#111'}),
|
|
321
|
+
);
|
|
322
|
+
});
|
|
323
|
+
const root = tree.root.findByProps({testID: 'runtime-footer-marquee-text'});
|
|
324
|
+
renderer.act(() => {
|
|
325
|
+
root.props.onLayout({nativeEvent: {layout: {width: 400, height: 12}}});
|
|
326
|
+
});
|
|
327
|
+
renderer.act(() => {
|
|
328
|
+
tree.root.findAllByType('Text')[0].props.onLayout({
|
|
329
|
+
nativeEvent: {layout: {width: 40, height: 12}},
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
assert.equal(lastLoopConfig, null);
|
|
333
|
+
assert.equal(tree.root.findAllByType('Text').length, 1);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
@@ -3,6 +3,7 @@ const {test} = require('node:test')
|
|
|
3
3
|
|
|
4
4
|
const {
|
|
5
5
|
getRuntimeFooterRotationEntries,
|
|
6
|
+
getRuntimeFooterTickerText,
|
|
6
7
|
getRuntimeFooterText,
|
|
7
8
|
getRuntimeFooterTextLines,
|
|
8
9
|
} = require('../../../react/utils/runtimeFooterText')
|
|
@@ -86,3 +87,36 @@ test('returns empty string when footer text is absent', () => {
|
|
|
86
87
|
assert.equal(getRuntimeFooterText(null, []), '')
|
|
87
88
|
assert.deepEqual(getRuntimeFooterTextLines(''), [])
|
|
88
89
|
})
|
|
90
|
+
|
|
91
|
+
test('ticker text: user text first, then the system text, joined by a bullet', () => {
|
|
92
|
+
const companyFooterText =
|
|
93
|
+
'www.controleonline.com \u2022 (11) 5555-5159 (Comercial) \u2022 (11) 3136-0353 (Suporte)'
|
|
94
|
+
const primaryText = 'web \u2022 MANAGER (179.125.133.217) / v1.10.236'
|
|
95
|
+
|
|
96
|
+
assert.equal(
|
|
97
|
+
getRuntimeFooterTickerText({companyFooterText, primaryText}),
|
|
98
|
+
`${companyFooterText} \u2022 ${primaryText}`,
|
|
99
|
+
)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('ticker text: multiple user lines keep their order before the system text', () => {
|
|
103
|
+
assert.equal(
|
|
104
|
+
getRuntimeFooterTickerText({
|
|
105
|
+
companyFooterText: 'linha 1\nlinha 2',
|
|
106
|
+
primaryText: 'web \u2022 PDV / v1',
|
|
107
|
+
}),
|
|
108
|
+
'linha 1 \u2022 linha 2 \u2022 web \u2022 PDV / v1',
|
|
109
|
+
)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('ticker text: shows only the available text, or nothing', () => {
|
|
113
|
+
assert.equal(
|
|
114
|
+
getRuntimeFooterTickerText({companyFooterText: '', primaryText: 'web \u2022 PDV / v1'}),
|
|
115
|
+
'web \u2022 PDV / v1',
|
|
116
|
+
)
|
|
117
|
+
assert.equal(
|
|
118
|
+
getRuntimeFooterTickerText({companyFooterText: 'Somente usuario', primaryText: ''}),
|
|
119
|
+
'Somente usuario',
|
|
120
|
+
)
|
|
121
|
+
assert.equal(getRuntimeFooterTickerText({companyFooterText: '', primaryText: ''}), '')
|
|
122
|
+
})
|