embedded-react 0.21.0 → 0.22.0
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/README.md +2 -2
- package/aot/compile.mjs +1 -1
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/check.mjs +1 -1
- package/aot/compiler/collect.mjs +1 -1
- package/aot/compiler/elements/button.mjs +3 -3
- package/aot/compiler/elements/image-background.mjs +1 -1
- package/aot/compiler/elements/props.mjs +10 -6
- package/aot/compiler/elements/section-list.mjs +1 -1
- package/aot/compiler/expressions.mjs +29 -2
- package/aot/compiler/handlers.mjs +73 -16
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/lower.mjs +12 -0
- package/aot/compiler/nodes.mjs +17 -9
- package/aot/compiler/out.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +36 -2
- package/aot/compiler/package/format.mjs +5 -3
- package/aot/compiler/package/lower.mjs +53 -19
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/style-text.mjs +2 -2
- package/aot/compiler/svg.mjs +6 -3
- package/aot/compiler/updaters.mjs +1 -0
- package/aot/style-map.mjs +44 -1
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +84 -101
- package/cli.mjs +482 -621
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +144 -200
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +93 -123
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +155 -2
- package/src/embedded-react/index.js +26 -19
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -146
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/nativeModule.js +0 -462
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// Button — RN's pre-styled button, as a plain component over <Pressable> + <Text>. No engine node of
|
|
18
17
|
// its own:
|
|
19
18
|
//
|
|
@@ -28,70 +27,47 @@
|
|
|
28
27
|
// Like RN's, this Button takes NO style prop — that is the whole point of it, and the escape hatch is
|
|
29
28
|
// the same: drop to <Pressable> + <Text> and style them yourself. `color` and `disabled` are the two
|
|
30
29
|
// knobs, exactly as upstream.
|
|
31
|
-
import {createElement} from 'react';
|
|
32
|
-
import {Text} from './components.
|
|
33
|
-
import {Pressable} from './Pressable.
|
|
34
|
-
import {createPropWarner, RN_PLATFORM_NO_OPS} from './warn-props.
|
|
35
|
-
|
|
30
|
+
import { createElement } from 'react';
|
|
31
|
+
import { Text } from './components.mjs';
|
|
32
|
+
import { Pressable } from './Pressable.mjs';
|
|
33
|
+
import { createPropWarner, RN_PLATFORM_NO_OPS } from './warn-props.mjs';
|
|
36
34
|
// RN's Button styles are Platform.select({ios, android}) and Platform.OS is 'embedded', so neither
|
|
37
35
|
// branch applies. These are the android ones — a filled, rounded button — because a panel button
|
|
38
36
|
// should read as a button before it is styled, and the ios branch is bare text. RN's `elevation: 4`
|
|
39
37
|
// is dropped: shadows are compile-gated (ERUI_SHADOWS) and off in every board config here, so it
|
|
40
38
|
// would be a prop marshaled on every commit to paint nothing.
|
|
41
39
|
const styles = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
button: { backgroundColor: '#2196F3', borderRadius: 2 },
|
|
41
|
+
buttonDisabled: { backgroundColor: '#dfdfdf' },
|
|
42
|
+
text: { color: '#ffffff', textAlign: 'center', padding: 8, fontWeight: '500' },
|
|
43
|
+
textDisabled: { color: '#a1a1a1' },
|
|
46
44
|
};
|
|
47
|
-
|
|
48
45
|
/** The props that do something here. RN's rest are OS services with nothing to wrap on an MCU. */
|
|
49
46
|
const SUPPORTED = ['title', 'onPress', 'color', 'disabled'];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
'Button',
|
|
53
|
-
SUPPORTED,
|
|
54
|
-
"it is RN's fixed-style button — for a button you style yourself, use <Pressable> + <Text> " +
|
|
55
|
-
'(the same tree this renders).',
|
|
56
|
-
RN_PLATFORM_NO_OPS,
|
|
57
|
-
);
|
|
58
|
-
|
|
47
|
+
const warnUnsupportedProps = createPropWarner('Button', SUPPORTED, "it is RN's fixed-style button — for a button you style yourself, use <Pressable> + <Text> " +
|
|
48
|
+
'(the same tree this renders).', RN_PLATFORM_NO_OPS);
|
|
59
49
|
/**
|
|
60
50
|
* A pre-styled press target with a centred label.
|
|
61
51
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @param {(event: object) => void} [props.onPress] Press handler. Not attached while `disabled`.
|
|
67
|
-
* @param {string} [props.color] Fill colour, replacing the default blue.
|
|
68
|
-
* @param {boolean} [props.disabled] Greys the button out and stops it responding to presses.
|
|
69
|
-
* @returns {*} A <Pressable> wrapping a single <Text>.
|
|
52
|
+
* Missing or empty props render an unlabelled button, rather than throwing on a device where a
|
|
53
|
+
* render-time throw takes the whole app down (RN `invariant`s on a missing title). The title is coerced
|
|
54
|
+
* to a string and not upper-cased (RN does that on Android, and an upper-cased glyph an app never wrote
|
|
55
|
+
* is a glyph the font bake never baked). `onPress` is not attached while `disabled`.
|
|
70
56
|
*/
|
|
71
57
|
export function Button(props = {}) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{
|
|
87
|
-
style: buttonStyles,
|
|
88
|
-
disabled,
|
|
89
|
-
onPress,
|
|
90
|
-
},
|
|
91
|
-
createElement(
|
|
92
|
-
Text,
|
|
93
|
-
{style: textStyles},
|
|
94
|
-
title === undefined || title === null ? '' : String(title),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
58
|
+
const { title, onPress, color, disabled } = props;
|
|
59
|
+
warnUnsupportedProps(props);
|
|
60
|
+
const buttonStyles = [styles.button];
|
|
61
|
+
const textStyles = [styles.text];
|
|
62
|
+
if (color)
|
|
63
|
+
buttonStyles.push({ backgroundColor: color });
|
|
64
|
+
if (disabled) {
|
|
65
|
+
buttonStyles.push(styles.buttonDisabled);
|
|
66
|
+
textStyles.push(styles.textDisabled);
|
|
67
|
+
}
|
|
68
|
+
return createElement(Pressable, {
|
|
69
|
+
style: buttonStyles,
|
|
70
|
+
disabled,
|
|
71
|
+
onPress,
|
|
72
|
+
}, createElement(Text, { style: textStyles }, title === undefined || title === null ? '' : String(title)));
|
|
97
73
|
}
|
|
@@ -13,25 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
// Dimensions — RN analog over the host-injected `screen` global. A panel has no pixel-density or font
|
|
18
|
-
// setting, so `scale` and `fontScale` are 1, and 'window' and 'screen' are the same size.
|
|
19
16
|
export const Dimensions = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
},
|
|
17
|
+
get(dimension) {
|
|
18
|
+
if (dimension !== 'window' && dimension !== 'screen') {
|
|
19
|
+
throw new Error(`Dimensions.get: no dimension named "${dimension}"`);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
width: screen.width,
|
|
23
|
+
height: screen.height,
|
|
24
|
+
scale: 1,
|
|
25
|
+
fontScale: 1,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
32
28
|
};
|
|
33
|
-
|
|
34
29
|
// The panel's size. It is fixed while the app runs, so this never re-renders.
|
|
35
30
|
export function useWindowDimensions() {
|
|
36
|
-
|
|
31
|
+
return Dimensions.get('window');
|
|
37
32
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export const Easing = {
|
|
17
|
+
linear: 'linear',
|
|
18
|
+
ease: 'ease',
|
|
19
|
+
easeIn: 'easeIn',
|
|
20
|
+
easeOut: 'easeOut',
|
|
21
|
+
easeInOut: 'easeInOut',
|
|
22
|
+
quadIn: 'quadIn',
|
|
23
|
+
quadOut: 'quadOut',
|
|
24
|
+
quadInOut: 'quadInOut',
|
|
25
|
+
cubicIn: 'cubicIn',
|
|
26
|
+
cubicOut: 'cubicOut',
|
|
27
|
+
cubicInOut: 'cubicInOut',
|
|
28
|
+
bounceOut: 'bounceOut',
|
|
29
|
+
elasticOut: 'elasticOut',
|
|
30
|
+
/** Custom cubic-bezier curve via control points. */
|
|
31
|
+
bezier(x1, y1, x2, y2) {
|
|
32
|
+
return { x1, y1, x2, y2 };
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// FlatList — a thin API-compat wrapper over <ScrollView>, NOT a virtualized list.
|
|
18
17
|
//
|
|
19
18
|
// <FlatList data={items} keyExtractor={(it) => it.id}
|
|
@@ -32,57 +31,41 @@
|
|
|
32
31
|
// which performs the same rewrite at compile time. The two flows accept the SAME four props on
|
|
33
32
|
// purpose — a list that renders in the simulator must also compile for the device, so anything
|
|
34
33
|
// Flow B rejects is warned about here rather than silently forwarded.
|
|
35
|
-
import {createElement} from 'react';
|
|
36
|
-
import {ScrollView} from './components.
|
|
37
|
-
import {pushKeyedChild} from './list-child.
|
|
38
|
-
import {createPropWarner} from './warn-props.
|
|
39
|
-
|
|
34
|
+
import { createElement } from 'react';
|
|
35
|
+
import { ScrollView } from './components.mjs';
|
|
36
|
+
import { pushKeyedChild } from './list-child.mjs';
|
|
37
|
+
import { createPropWarner } from './warn-props.mjs';
|
|
40
38
|
/** The only props both flows honour. Everything else is a virtualization/platform knob with no meaning. */
|
|
41
39
|
const SUPPORTED = ['data', 'renderItem', 'keyExtractor', 'style'];
|
|
42
|
-
|
|
43
40
|
// Warns once about props that do nothing here and that the AOT refuses to compile, so a list built in
|
|
44
41
|
// the simulator doesn't fail the device build later.
|
|
45
|
-
const warnUnsupportedProps = createPropWarner(
|
|
46
|
-
'FlatList',
|
|
47
|
-
SUPPORTED,
|
|
48
|
-
'it is a thin <ScrollView> alias with no virtualization, and the AOT rejects these props outright ' +
|
|
42
|
+
const warnUnsupportedProps = createPropWarner('FlatList', SUPPORTED, 'it is a thin <ScrollView> alias with no virtualization, and the AOT rejects these props outright ' +
|
|
49
43
|
'("AOT: <FlatList> prop ... is not supported"). For headers/footers/separators/horizontal/' +
|
|
50
|
-
'onEndReached, use <ScrollView> + .map directly.'
|
|
51
|
-
);
|
|
52
|
-
|
|
44
|
+
'onEndReached, use <ScrollView> + .map directly.');
|
|
53
45
|
/**
|
|
54
46
|
* Renders `data` through `renderItem` into a <ScrollView>. Rows that render to nothing (null / false)
|
|
55
47
|
* are dropped, matching a plain `.map` + conditional.
|
|
56
48
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param {(item: *, index: number) => string|number} [props.keyExtractor] React key per row; defaults
|
|
61
|
-
* to the key `renderItem` already set, else the index.
|
|
62
|
-
* @param {object} [props.style] Forwarded to the ScrollView untouched.
|
|
63
|
-
* @returns {*} A <ScrollView> element holding one child per rendered row.
|
|
49
|
+
* Missing props, or a `data` that is not an array, render an empty scroller. A row's key is
|
|
50
|
+
* `keyExtractor`'s, else the one `renderItem` already set, else the index. `style` goes to the ScrollView
|
|
51
|
+
* untouched.
|
|
64
52
|
*/
|
|
65
53
|
export function FlatList(props = {}) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
? element.key
|
|
82
|
-
: String(index),
|
|
83
|
-
);
|
|
54
|
+
const { data, renderItem, keyExtractor, style } = props;
|
|
55
|
+
warnUnsupportedProps(props);
|
|
56
|
+
const rows = [];
|
|
57
|
+
if (Array.isArray(data) && typeof renderItem === 'function') {
|
|
58
|
+
for (let index = 0; index < data.length; index++) {
|
|
59
|
+
const item = data[index];
|
|
60
|
+
const row = renderItem({ item, index });
|
|
61
|
+
// The key is built lazily: pushKeyedChild calls this only for a row that can hold one, so
|
|
62
|
+
// keyExtractor never runs for a row that rendered nothing or for a raw string.
|
|
63
|
+
pushKeyedChild(rows, row, element => keyExtractor
|
|
64
|
+
? String(keyExtractor(item, index))
|
|
65
|
+
: element.key !== null && element.key !== undefined
|
|
66
|
+
? element.key
|
|
67
|
+
: String(index));
|
|
68
|
+
}
|
|
84
69
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return createElement(ScrollView, style === undefined ? null : {style}, rows);
|
|
70
|
+
return createElement(ScrollView, style === undefined ? null : { style }, rows);
|
|
88
71
|
}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// ImageBackground — RN's "content on top of a picture" wrapper, as a plain component. No engine node
|
|
18
17
|
// of its own:
|
|
19
18
|
//
|
|
@@ -33,10 +32,9 @@
|
|
|
33
32
|
// the container's width/height onto the image to undo <Image>'s own sizing. Ours doesn't size itself,
|
|
34
33
|
// so the inset alone fills the box — and since an absolute child resolves its insets against the
|
|
35
34
|
// container's PADDING box, as in RN, the picture fills the whole container even when it has padding.
|
|
36
|
-
import {createElement, forwardRef} from 'react';
|
|
37
|
-
import {View, Image} from './components.
|
|
38
|
-
import {StyleSheet} from './StyleSheet.
|
|
39
|
-
|
|
35
|
+
import { createElement, forwardRef } from 'react';
|
|
36
|
+
import { View, Image } from './components.mjs';
|
|
37
|
+
import { StyleSheet } from './StyleSheet.mjs';
|
|
40
38
|
/**
|
|
41
39
|
* A <View> with an <Image> stretched behind its children.
|
|
42
40
|
*
|
|
@@ -45,23 +43,14 @@ import {StyleSheet} from './StyleSheet.js';
|
|
|
45
43
|
* `onLayout` handlers on the image rather than the container, and the children paint on top of it, so
|
|
46
44
|
* a handler meant for the whole area belongs on a <Pressable> around this component.
|
|
47
45
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param {*} [props.imageStyle] Style merged over the fill, for `borderRadius`, `opacity`, `tintColor`.
|
|
51
|
-
* @param {*} [props.imageRef] Ref to the <Image> node (the outer `ref` goes to the <View>).
|
|
52
|
-
* @param {*} [props.children] Rendered above the picture, laid out against the container.
|
|
53
|
-
* @returns {*} A <View> whose first child is the backing <Image>.
|
|
46
|
+
* `imageStyle` is merged over the fill, for `borderRadius`, `opacity`, `tintColor`. `imageRef` is a ref to
|
|
47
|
+
* the <Image> node (the outer `ref` goes to the <View>). The children are laid out against the container.
|
|
54
48
|
*/
|
|
55
49
|
export const ImageBackground = forwardRef(function ImageBackground(props, ref) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
style: [StyleSheet.absoluteFill, imageStyle],
|
|
63
|
-
ref: imageRef,
|
|
64
|
-
}),
|
|
65
|
-
children,
|
|
66
|
-
);
|
|
50
|
+
const { children, style, imageStyle, imageRef, ...imageProps } = props;
|
|
51
|
+
return createElement(View, { style, ref }, createElement(Image, {
|
|
52
|
+
...imageProps,
|
|
53
|
+
style: [StyleSheet.absoluteFill, imageStyle],
|
|
54
|
+
ref: imageRef,
|
|
55
|
+
}), children);
|
|
67
56
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
// Keyboard — RN's Keyboard over the engine's on-screen keyboard, which shows while a <TextInput> has the
|
|
17
|
+
// focus. A build without it (ERUI_ONSCREEN_KEYBOARD=0) has no keyboard to report: dismiss() still takes
|
|
18
|
+
// the focus away, but no event fires.
|
|
19
|
+
import { NativeUI } from '../native-ui.mjs';
|
|
20
|
+
const listeners = {
|
|
21
|
+
keyboardWillShow: new Set(),
|
|
22
|
+
keyboardDidShow: new Set(),
|
|
23
|
+
keyboardWillHide: new Set(),
|
|
24
|
+
keyboardDidHide: new Set(),
|
|
25
|
+
};
|
|
26
|
+
let subscribed = false;
|
|
27
|
+
// Where the keyboard last showed, for the hide events.
|
|
28
|
+
let lastFrame = { x: 0, y: 0, width: 0, height: 0 };
|
|
29
|
+
const coordinates = (frame) => ({
|
|
30
|
+
screenX: frame.x,
|
|
31
|
+
screenY: frame.y,
|
|
32
|
+
width: frame.width,
|
|
33
|
+
height: frame.height,
|
|
34
|
+
});
|
|
35
|
+
function emit(eventName, event) {
|
|
36
|
+
// A copy, so a listener can remove itself.
|
|
37
|
+
for (const listener of [...listeners[eventName]])
|
|
38
|
+
listener(event);
|
|
39
|
+
}
|
|
40
|
+
function onKeyboardChange(shown) {
|
|
41
|
+
if (shown) {
|
|
42
|
+
lastFrame = NativeUI.keyboardFrame() ?? lastFrame;
|
|
43
|
+
const event = { endCoordinates: coordinates(lastFrame) };
|
|
44
|
+
emit('keyboardWillShow', event);
|
|
45
|
+
emit('keyboardDidShow', event);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// It ends just below the screen.
|
|
49
|
+
const hidden = { ...lastFrame, y: lastFrame.y + lastFrame.height };
|
|
50
|
+
const event = { endCoordinates: coordinates(hidden) };
|
|
51
|
+
emit('keyboardWillHide', event);
|
|
52
|
+
emit('keyboardDidHide', event);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export const Keyboard = {
|
|
56
|
+
// Nothing animates, so each "will" event fires just before its "did".
|
|
57
|
+
addListener(eventName, listener) {
|
|
58
|
+
const set = listeners[eventName];
|
|
59
|
+
if (!set) {
|
|
60
|
+
throw new Error(`Keyboard.addListener: no event named "${eventName}"`);
|
|
61
|
+
}
|
|
62
|
+
if (!subscribed) {
|
|
63
|
+
NativeUI.setKeyboardListener(onKeyboardChange);
|
|
64
|
+
subscribed = true;
|
|
65
|
+
}
|
|
66
|
+
set.add(listener);
|
|
67
|
+
return { remove: () => set.delete(listener) };
|
|
68
|
+
},
|
|
69
|
+
removeAllListeners(eventName) {
|
|
70
|
+
listeners[eventName]?.clear();
|
|
71
|
+
},
|
|
72
|
+
dismiss() {
|
|
73
|
+
NativeUI.dismissKeyboard();
|
|
74
|
+
},
|
|
75
|
+
isVisible() {
|
|
76
|
+
return NativeUI.keyboardFrame() !== undefined;
|
|
77
|
+
},
|
|
78
|
+
metrics() {
|
|
79
|
+
const frame = NativeUI.keyboardFrame();
|
|
80
|
+
return frame ? coordinates(frame) : undefined;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
@@ -13,43 +13,32 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// LayoutAnimation — the React Native analog. Calling configureNext(...) before a state update that
|
|
18
17
|
// changes layout makes the engine tween every node whose computed rect moved (instead of snapping)
|
|
19
18
|
// on the next commit. Backed by the engine's er_layout_animation_configure_next; the tween advances in C
|
|
20
19
|
// each frame (er_layout_animation_tick), so there's no per-frame JS.
|
|
21
|
-
import {NativeUI} from '../native-ui.
|
|
22
|
-
import {
|
|
23
|
-
Types,
|
|
24
|
-
Properties,
|
|
25
|
-
Presets,
|
|
26
|
-
toEngineConfig,
|
|
27
|
-
create,
|
|
28
|
-
DEFAULT_DURATION_MS,
|
|
29
|
-
} from './layout-anim-config.js';
|
|
30
|
-
|
|
20
|
+
import { NativeUI } from '../native-ui.mjs';
|
|
21
|
+
import { Types, Properties, Presets, toEngineConfig, create, DEFAULT_DURATION_MS, } from './layout-anim-config.mjs';
|
|
31
22
|
/**
|
|
32
23
|
* Arms a layout animation for the next commit. Call right before the setState that changes layout.
|
|
33
24
|
* onAnimationDidEnd is approximated with a timer (the engine config carries no completion hook).
|
|
34
25
|
*/
|
|
35
26
|
export function configureNext(config, onAnimationDidEnd) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
27
|
+
NativeUI.configureNextLayoutAnimation(toEngineConfig(config));
|
|
28
|
+
if (typeof onAnimationDidEnd === 'function') {
|
|
29
|
+
const durationMs = config && typeof config.duration === 'number'
|
|
30
|
+
? config.duration
|
|
31
|
+
: DEFAULT_DURATION_MS;
|
|
32
|
+
setTimeout(onAnimationDidEnd, durationMs);
|
|
33
|
+
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
export const LayoutAnimation = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
configureNext,
|
|
37
|
+
create,
|
|
38
|
+
Types,
|
|
39
|
+
Properties,
|
|
40
|
+
Presets,
|
|
41
|
+
easeInEaseOut: (onDone) => configureNext(Presets.easeInEaseOut, onDone),
|
|
42
|
+
linear: (onDone) => configureNext(Presets.linear, onDone),
|
|
43
|
+
spring: (onDone) => configureNext(Presets.spring, onDone),
|
|
55
44
|
};
|