@symbiote-native/angular 0.0.0-canary-20260724081123
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/LICENSE +21 -0
- package/README.md +157 -0
- package/babel-linker.cjs +7 -0
- package/babel-register-composed.cjs +127 -0
- package/bin/symbiote-angular-dev.cjs +93 -0
- package/build/angular/anchor-host-registry.d.ts +2 -0
- package/build/angular/anchor-host-registry.js +84 -0
- package/build/angular/anchor-host-registry.js.map +1 -0
- package/build/angular/bootstrap.d.ts +7 -0
- package/build/angular/bootstrap.js +15 -0
- package/build/angular/bootstrap.js.map +1 -0
- package/build/angular/components/activity-indicator/index.android.d.ts +12 -0
- package/build/angular/components/activity-indicator/index.android.js +21 -0
- package/build/angular/components/activity-indicator/index.android.js.map +1 -0
- package/build/angular/components/activity-indicator/index.d.ts +1 -0
- package/build/angular/components/activity-indicator/index.ios.d.ts +8 -0
- package/build/angular/components/activity-indicator/index.ios.js +21 -0
- package/build/angular/components/activity-indicator/index.ios.js.map +1 -0
- package/build/angular/components/activity-indicator/index.js +4 -0
- package/build/angular/components/activity-indicator/index.js.map +1 -0
- package/build/angular/components/activity-indicator/shared.d.ts +67 -0
- package/build/angular/components/activity-indicator/shared.js +260 -0
- package/build/angular/components/activity-indicator/shared.js.map +1 -0
- package/build/angular/components/button.d.ts +63 -0
- package/build/angular/components/button.js +332 -0
- package/build/angular/components/button.js.map +1 -0
- package/build/angular/components/flat-list/index.d.ts +122 -0
- package/build/angular/components/flat-list/index.js +688 -0
- package/build/angular/components/flat-list/index.js.map +1 -0
- package/build/angular/components/image/index.android.d.ts +10 -0
- package/build/angular/components/image/index.android.js +59 -0
- package/build/angular/components/image/index.android.js.map +1 -0
- package/build/angular/components/image/index.d.ts +1 -0
- package/build/angular/components/image/index.ios.d.ts +10 -0
- package/build/angular/components/image/index.ios.js +59 -0
- package/build/angular/components/image/index.ios.js.map +1 -0
- package/build/angular/components/image/index.js +3 -0
- package/build/angular/components/image/index.js.map +1 -0
- package/build/angular/components/image/shared.d.ts +101 -0
- package/build/angular/components/image/shared.js +406 -0
- package/build/angular/components/image/shared.js.map +1 -0
- package/build/angular/components/image-background.d.ts +81 -0
- package/build/angular/components/image-background.js +418 -0
- package/build/angular/components/image-background.js.map +1 -0
- package/build/angular/components/input-accessory-view/index.d.ts +60 -0
- package/build/angular/components/input-accessory-view/index.js +251 -0
- package/build/angular/components/input-accessory-view/index.js.map +1 -0
- package/build/angular/components/keyboard-avoiding-view/index.d.ts +82 -0
- package/build/angular/components/keyboard-avoiding-view/index.js +358 -0
- package/build/angular/components/keyboard-avoiding-view/index.js.map +1 -0
- package/build/angular/components/modal/index.d.ts +92 -0
- package/build/angular/components/modal/index.js +360 -0
- package/build/angular/components/modal/index.js.map +1 -0
- package/build/angular/components/pressable/index.d.ts +123 -0
- package/build/angular/components/pressable/index.js +420 -0
- package/build/angular/components/pressable/index.js.map +1 -0
- package/build/angular/components/refresh-control/index.d.ts +86 -0
- package/build/angular/components/refresh-control/index.js +342 -0
- package/build/angular/components/refresh-control/index.js.map +1 -0
- package/build/angular/components/safe-area-view/index.d.ts +57 -0
- package/build/angular/components/safe-area-view/index.js +248 -0
- package/build/angular/components/safe-area-view/index.js.map +1 -0
- package/build/angular/components/scroll-view/index.android.d.ts +21 -0
- package/build/angular/components/scroll-view/index.android.js +235 -0
- package/build/angular/components/scroll-view/index.android.js.map +1 -0
- package/build/angular/components/scroll-view/index.d.ts +3 -0
- package/build/angular/components/scroll-view/index.ios.d.ts +9 -0
- package/build/angular/components/scroll-view/index.ios.js +86 -0
- package/build/angular/components/scroll-view/index.ios.js.map +1 -0
- package/build/angular/components/scroll-view/index.js +6 -0
- package/build/angular/components/scroll-view/index.js.map +1 -0
- package/build/angular/components/scroll-view/projection.d.ts +32 -0
- package/build/angular/components/scroll-view/projection.js +334 -0
- package/build/angular/components/scroll-view/projection.js.map +1 -0
- package/build/angular/components/scroll-view/shared.d.ts +230 -0
- package/build/angular/components/scroll-view/shared.js +682 -0
- package/build/angular/components/scroll-view/shared.js.map +1 -0
- package/build/angular/components/scroll-view/sticky-header.d.ts +40 -0
- package/build/angular/components/scroll-view/sticky-header.js +225 -0
- package/build/angular/components/scroll-view/sticky-header.js.map +1 -0
- package/build/angular/components/section-list/index.d.ts +116 -0
- package/build/angular/components/section-list/index.js +641 -0
- package/build/angular/components/section-list/index.js.map +1 -0
- package/build/angular/components/switch/index.android.d.ts +20 -0
- package/build/angular/components/switch/index.android.js +70 -0
- package/build/angular/components/switch/index.android.js.map +1 -0
- package/build/angular/components/switch/index.d.ts +1 -0
- package/build/angular/components/switch/index.ios.d.ts +19 -0
- package/build/angular/components/switch/index.ios.js +69 -0
- package/build/angular/components/switch/index.ios.js.map +1 -0
- package/build/angular/components/switch/index.js +4 -0
- package/build/angular/components/switch/index.js.map +1 -0
- package/build/angular/components/switch/shared.d.ts +40 -0
- package/build/angular/components/switch/shared.js +127 -0
- package/build/angular/components/switch/shared.js.map +1 -0
- package/build/angular/components/text-input.d.ts +153 -0
- package/build/angular/components/text-input.js +599 -0
- package/build/angular/components/text-input.js.map +1 -0
- package/build/angular/components/touchable/index.d.ts +245 -0
- package/build/angular/components/touchable/index.js +1186 -0
- package/build/angular/components/touchable/index.js.map +1 -0
- package/build/angular/components/touchable-native-feedback/index.d.ts +83 -0
- package/build/angular/components/touchable-native-feedback/index.js +371 -0
- package/build/angular/components/touchable-native-feedback/index.js.map +1 -0
- package/build/angular/components/virtualized-list/directives.d.ts +54 -0
- package/build/angular/components/virtualized-list/directives.js +153 -0
- package/build/angular/components/virtualized-list/directives.js.map +1 -0
- package/build/angular/components/virtualized-list/index.d.ts +253 -0
- package/build/angular/components/virtualized-list/index.js +1031 -0
- package/build/angular/components/virtualized-list/index.js.map +1 -0
- package/build/angular/components/virtualized-section-list/directives.d.ts +37 -0
- package/build/angular/components/virtualized-section-list/directives.js +76 -0
- package/build/angular/components/virtualized-section-list/directives.js.map +1 -0
- package/build/angular/components/virtualized-section-list/index.d.ts +178 -0
- package/build/angular/components/virtualized-section-list/index.js +720 -0
- package/build/angular/components/virtualized-section-list/index.js.map +1 -0
- package/build/angular/components.d.ts +39 -0
- package/build/angular/components.js +38 -0
- package/build/angular/components.js.map +1 -0
- package/build/angular/create-portal/index.d.ts +22 -0
- package/build/angular/create-portal/index.js +74 -0
- package/build/angular/create-portal/index.js.map +1 -0
- package/build/angular/create-tunnel/index.d.ts +34 -0
- package/build/angular/create-tunnel/index.js +126 -0
- package/build/angular/create-tunnel/index.js.map +1 -0
- package/build/angular/descriptor-to-angular/index.d.ts +22 -0
- package/build/angular/descriptor-to-angular/index.js +142 -0
- package/build/angular/descriptor-to-angular/index.js.map +1 -0
- package/build/angular/host-instance/index.d.ts +2 -0
- package/build/angular/host-instance/index.js +37 -0
- package/build/angular/host-instance/index.js.map +1 -0
- package/build/angular/index.d.ts +22 -0
- package/build/angular/index.js +46 -0
- package/build/angular/index.js.map +1 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.d.ts +14 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.js +91 -0
- package/build/angular/modules/animated/animated-leaf-binder/index.js.map +1 -0
- package/build/angular/modules/animated/animated-leaf-binder.d.ts +14 -0
- package/build/angular/modules/animated/animated-leaf-binder.js +91 -0
- package/build/angular/modules/animated/animated-leaf-binder.js.map +1 -0
- package/build/angular/modules/animated/create-animated-component.d.ts +59 -0
- package/build/angular/modules/animated/create-animated-component.js +364 -0
- package/build/angular/modules/animated/create-animated-component.js.map +1 -0
- package/build/angular/modules/animated/index.d.ts +51 -0
- package/build/angular/modules/animated/index.js +59 -0
- package/build/angular/modules/animated/index.js.map +1 -0
- package/build/angular/modules/app-registry/index.d.ts +7 -0
- package/build/angular/modules/app-registry/index.js +23 -0
- package/build/angular/modules/app-registry/index.js.map +1 -0
- package/build/angular/modules/status-bar/index.d.ts +20 -0
- package/build/angular/modules/status-bar/index.js +59 -0
- package/build/angular/modules/status-bar/index.js.map +1 -0
- package/build/angular/primitives/index.d.ts +63 -0
- package/build/angular/primitives/index.js +189 -0
- package/build/angular/primitives/index.js.map +1 -0
- package/build/angular/primitives/shared.d.ts +88 -0
- package/build/angular/primitives/shared.js +171 -0
- package/build/angular/primitives/shared.js.map +1 -0
- package/build/angular/render/index.d.ts +11 -0
- package/build/angular/render/index.js +171 -0
- package/build/angular/render/index.js.map +1 -0
- package/build/angular/renderer/index.d.ts +37 -0
- package/build/angular/renderer/index.js +301 -0
- package/build/angular/renderer/index.js.map +1 -0
- package/build/angular/services/color-scheme.service.d.ts +16 -0
- package/build/angular/services/color-scheme.service.js +31 -0
- package/build/angular/services/color-scheme.service.js.map +1 -0
- package/build/angular/services/index.d.ts +2 -0
- package/build/angular/services/index.js +3 -0
- package/build/angular/services/index.js.map +1 -0
- package/build/angular/services/window-dimensions.service.d.ts +16 -0
- package/build/angular/services/window-dimensions.service.js +42 -0
- package/build/angular/services/window-dimensions.service.js.map +1 -0
- package/metro-config.cjs +48 -0
- package/metro-css-parser.cjs +13 -0
- package/package.json +80 -0
- package/src/__tests__/responder-change-detection.test.ts +102 -0
- package/src/__tests__/responder-nested-cd.test.ts +113 -0
- package/src/anchor-host-registry.ts +88 -0
- package/src/angular-gaps.test.ts +142 -0
- package/src/angular-imports.test.ts +100 -0
- package/src/bootstrap.ts +26 -0
- package/src/components/activity-indicator/activity-indicator-class-style.test.ts +44 -0
- package/src/components/activity-indicator/activity-indicator.test.ts +131 -0
- package/src/components/activity-indicator/index.android.ts +16 -0
- package/src/components/activity-indicator/index.ios.ts +17 -0
- package/src/components/activity-indicator/index.ts +4 -0
- package/src/components/activity-indicator/shared.ts +206 -0
- package/src/components/button.ts +193 -0
- package/src/components/flat-list/column-wrapper-style-class.test.ts +116 -0
- package/src/components/flat-list/flat-list-array-style.test.ts +131 -0
- package/src/components/flat-list/flat-list-class-style.test.ts +74 -0
- package/src/components/flat-list/flat-list-scroll-containment.test.ts +107 -0
- package/src/components/flat-list/flat-list.test.ts +99 -0
- package/src/components/flat-list/index.ts +574 -0
- package/src/components/image/image-class-style.test.ts +46 -0
- package/src/components/image/index.android.ts +48 -0
- package/src/components/image/index.ios.ts +48 -0
- package/src/components/image/index.ts +3 -0
- package/src/components/image/shared.ts +479 -0
- package/src/components/image-background-class-style.test.ts +48 -0
- package/src/components/image-background-style-class.test.ts +79 -0
- package/src/components/image-background.ts +270 -0
- package/src/components/input-accessory-view/index.ts +185 -0
- package/src/components/input-accessory-view/input-accessory-view.test.ts +43 -0
- package/src/components/keyboard-avoiding-view/index.ts +303 -0
- package/src/components/keyboard-avoiding-view/keyboard-avoiding-view.test.ts +54 -0
- package/src/components/modal/index.ts +299 -0
- package/src/components/modal/modal.test.ts +43 -0
- package/src/components/pressable/index.ts +373 -0
- package/src/components/pressable/pressable.test.ts +85 -0
- package/src/components/refresh-control/index.ts +284 -0
- package/src/components/refresh-control/refresh-control.test.ts +41 -0
- package/src/components/safe-area-view/index.ts +177 -0
- package/src/components/safe-area-view/safe-area-view.test.ts +43 -0
- package/src/components/scroll-view/android-scroll-view-axis-projection.test.ts +123 -0
- package/src/components/scroll-view/content-container-style-class.test.ts +75 -0
- package/src/components/scroll-view/index.android.ts +190 -0
- package/src/components/scroll-view/index.ios.ts +79 -0
- package/src/components/scroll-view/index.ts +7 -0
- package/src/components/scroll-view/projection.ts +414 -0
- package/src/components/scroll-view/scroll-view-class-style.test.ts +134 -0
- package/src/components/scroll-view/scroll-view-projection.test.ts +194 -0
- package/src/components/scroll-view/shared.ts +844 -0
- package/src/components/scroll-view/sticky-header.ts +255 -0
- package/src/components/section-list/index.ts +445 -0
- package/src/components/switch/android-switch-class.test.ts +42 -0
- package/src/components/switch/index.android.ts +61 -0
- package/src/components/switch/index.ios.ts +60 -0
- package/src/components/switch/index.ts +4 -0
- package/src/components/switch/shared.ts +197 -0
- package/src/components/switch/switch.test.ts +92 -0
- package/src/components/text-input-class-style.test.ts +54 -0
- package/src/components/text-input.ts +531 -0
- package/src/components/touchable/index.ts +629 -0
- package/src/components/touchable/touchable.test.ts +102 -0
- package/src/components/touchable-native-feedback/index.ts +254 -0
- package/src/components/touchable-native-feedback/touchable-native-feedback.test.ts +49 -0
- package/src/components/virtualized-list/directives.ts +168 -0
- package/src/components/virtualized-list/index.ts +992 -0
- package/src/components/virtualized-list/virtualized-list-class-style.test.ts +76 -0
- package/src/components/virtualized-section-list/directives.ts +90 -0
- package/src/components/virtualized-section-list/index.ts +601 -0
- package/src/components/virtualized-section-list/virtualized-section-list-class-style.test.ts +60 -0
- package/src/components.ts +149 -0
- package/src/create-portal/create-portal.test.ts +90 -0
- package/src/create-portal/index.ts +74 -0
- package/src/create-tunnel/create-tunnel.test.ts +120 -0
- package/src/create-tunnel/index.ts +136 -0
- package/src/descriptor-to-angular/descriptor-outlet.test.ts +94 -0
- package/src/descriptor-to-angular/index.ts +190 -0
- package/src/host-instance/host-instance.test.ts +49 -0
- package/src/host-instance/index.ts +36 -0
- package/src/index.ts +261 -0
- package/src/modules/animated/animated-leaf-binder/animated-leaf-binder.test.ts +116 -0
- package/src/modules/animated/animated-leaf-binder/index.ts +101 -0
- package/src/modules/animated/animated-leaf-binder.test.ts +116 -0
- package/src/modules/animated/animated-leaf-binder.ts +101 -0
- package/src/modules/animated/animated-scroll-view.test.ts +102 -0
- package/src/modules/animated/create-animated-component.ts +365 -0
- package/src/modules/animated/index.ts +105 -0
- package/src/modules/app-registry/app-registry.test.ts +106 -0
- package/src/modules/app-registry/index.ts +60 -0
- package/src/modules/status-bar/index.ts +57 -0
- package/src/modules/status-bar/status-bar.test.ts +50 -0
- package/src/primitives/index.ts +119 -0
- package/src/primitives/shared.ts +190 -0
- package/src/render/index.ts +235 -0
- package/src/render/render.test.ts +147 -0
- package/src/renderer/index.ts +347 -0
- package/src/renderer/renderer.test.ts +203 -0
- package/src/services/color-scheme.service.ts +27 -0
- package/src/services/index.ts +2 -0
- package/src/services/services.test.ts +163 -0
- package/src/services/window-dimensions.service.ts +41 -0
- package/tsconfig.angular.base.json +30 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { Directive, EventEmitter, Output } from '@angular/core';
|
|
2
|
+
import { renderSwitch, resolveAccessibilityProps } from '@symbiote-native/components';
|
|
3
|
+
import type {
|
|
4
|
+
ISwitchPlatform,
|
|
5
|
+
ISwitchProps,
|
|
6
|
+
ISwitchState,
|
|
7
|
+
ISwitchTrackColor,
|
|
8
|
+
} from '@symbiote-native/components';
|
|
9
|
+
import {
|
|
10
|
+
createInitialSwitchState,
|
|
11
|
+
shouldSnapBack,
|
|
12
|
+
switchReducer,
|
|
13
|
+
valueFromChange,
|
|
14
|
+
} from '@symbiote-native/components';
|
|
15
|
+
import {
|
|
16
|
+
dispatchViewCommand,
|
|
17
|
+
dlog,
|
|
18
|
+
isSymbioteNode,
|
|
19
|
+
whenCommitted,
|
|
20
|
+
type ISymbioteEvent,
|
|
21
|
+
type ISymbioteNode,
|
|
22
|
+
type IStyleProp,
|
|
23
|
+
type IViewStyle,
|
|
24
|
+
} from '@symbiote-native/engine';
|
|
25
|
+
|
|
26
|
+
export type { ISwitchProps, ISwitchTrackColor } from '@symbiote-native/components';
|
|
27
|
+
|
|
28
|
+
export type ISwitchInputs = Pick<
|
|
29
|
+
ISwitchProps,
|
|
30
|
+
| 'value'
|
|
31
|
+
| 'disabled'
|
|
32
|
+
| 'trackColor'
|
|
33
|
+
| 'thumbColor'
|
|
34
|
+
| 'ios_backgroundColor'
|
|
35
|
+
| 'style'
|
|
36
|
+
| 'nativeID'
|
|
37
|
+
| 'testID'
|
|
38
|
+
| 'accessibilityLabel'
|
|
39
|
+
| 'accessibilityRole'
|
|
40
|
+
| 'accessibilityState'
|
|
41
|
+
| 'accessibilityValue'
|
|
42
|
+
| 'accessibilityHint'
|
|
43
|
+
| 'accessible'
|
|
44
|
+
| 'role'
|
|
45
|
+
| 'aria-label'
|
|
46
|
+
| 'aria-disabled'
|
|
47
|
+
| 'aria-checked'
|
|
48
|
+
>;
|
|
49
|
+
|
|
50
|
+
type ISwitchHostPlatform = ISwitchPlatform & { snapBackCommand: string };
|
|
51
|
+
|
|
52
|
+
type IHostProps = Record<string, unknown>;
|
|
53
|
+
|
|
54
|
+
function readSwitchNode(value: unknown): ISymbioteNode | null {
|
|
55
|
+
if (isSymbioteNode(value)) return value;
|
|
56
|
+
if (
|
|
57
|
+
typeof value === 'object' &&
|
|
58
|
+
value !== null &&
|
|
59
|
+
'node' in value &&
|
|
60
|
+
isSymbioteNode(value.node)
|
|
61
|
+
) {
|
|
62
|
+
return value.node;
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isSwitchEvent(event: unknown): event is ISymbioteEvent {
|
|
68
|
+
return (
|
|
69
|
+
typeof event === 'object' &&
|
|
70
|
+
event !== null &&
|
|
71
|
+
'nativeEvent' in event &&
|
|
72
|
+
typeof event.nativeEvent === 'object' &&
|
|
73
|
+
event.nativeEvent !== null
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// @Directive() (no selector) is the Angular-sanctioned decorator for an abstract base whose
|
|
78
|
+
// concrete subclasses are real @Components — ngc's AOT build (NG2007) requires it the moment the
|
|
79
|
+
// base itself carries decorated members (@Output() here), mirroring ScrollViewBase.
|
|
80
|
+
@Directive()
|
|
81
|
+
export abstract class SwitchBase implements ISwitchInputs {
|
|
82
|
+
// The value/change lifecycle as real Angular events: `(valueChange)="onToggle($event)"`, not
|
|
83
|
+
// `[onValueChange]="onToggle"` — mirrors Pressable's press/hover @Output() conversion. Unlike
|
|
84
|
+
// Pressable's createPressHandlers, handleChange() below calls `.emit()` unconditionally: it needs
|
|
85
|
+
// no "was this bound" adapter because EventEmitter.emit() is already a safe no-op with no subscribers.
|
|
86
|
+
@Output() readonly valueChange = new EventEmitter<boolean>();
|
|
87
|
+
@Output() readonly change = new EventEmitter<ISymbioteEvent>();
|
|
88
|
+
value: boolean | undefined;
|
|
89
|
+
disabled: boolean | undefined;
|
|
90
|
+
trackColor: ISwitchTrackColor | undefined;
|
|
91
|
+
thumbColor: string | undefined;
|
|
92
|
+
ios_backgroundColor: string | undefined;
|
|
93
|
+
style: IStyleProp<IViewStyle> | undefined;
|
|
94
|
+
nativeID: string | undefined;
|
|
95
|
+
testID: string | undefined;
|
|
96
|
+
accessibilityLabel: string | undefined;
|
|
97
|
+
accessibilityRole: ISwitchInputs['accessibilityRole'];
|
|
98
|
+
accessibilityState: ISwitchInputs['accessibilityState'];
|
|
99
|
+
accessibilityValue: ISwitchInputs['accessibilityValue'];
|
|
100
|
+
accessibilityHint: string | undefined;
|
|
101
|
+
accessible: boolean | undefined;
|
|
102
|
+
role: ISwitchInputs['role'];
|
|
103
|
+
'aria-label': string | undefined;
|
|
104
|
+
'aria-disabled': boolean | undefined;
|
|
105
|
+
'aria-checked': boolean | 'mixed' | undefined;
|
|
106
|
+
|
|
107
|
+
protected abstract readonly platform: ISwitchHostPlatform;
|
|
108
|
+
private switchState: ISwitchState = createInitialSwitchState();
|
|
109
|
+
|
|
110
|
+
get hostProps(): IHostProps {
|
|
111
|
+
const props = resolveAccessibilityProps(this.inputProps());
|
|
112
|
+
const {
|
|
113
|
+
value,
|
|
114
|
+
disabled,
|
|
115
|
+
trackColor,
|
|
116
|
+
thumbColor,
|
|
117
|
+
ios_backgroundColor,
|
|
118
|
+
style,
|
|
119
|
+
onValueChange: _onValueChange,
|
|
120
|
+
...passthrough
|
|
121
|
+
} = props;
|
|
122
|
+
|
|
123
|
+
return renderSwitch(
|
|
124
|
+
{
|
|
125
|
+
value: value === true,
|
|
126
|
+
disabled,
|
|
127
|
+
trackColor,
|
|
128
|
+
thumbColor,
|
|
129
|
+
ios_backgroundColor,
|
|
130
|
+
style,
|
|
131
|
+
passthrough,
|
|
132
|
+
},
|
|
133
|
+
this.platform,
|
|
134
|
+
).props;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
handleChange(event: unknown, node: unknown): void {
|
|
138
|
+
if (!isSwitchEvent(event)) return;
|
|
139
|
+
this.change.emit(event);
|
|
140
|
+
const next = valueFromChange(event);
|
|
141
|
+
dlog(
|
|
142
|
+
`Switch onChange value=${String(next)} eventCount=${String(event.nativeEvent.eventCount)}`,
|
|
143
|
+
);
|
|
144
|
+
if (next === undefined) return;
|
|
145
|
+
|
|
146
|
+
this.valueChange.emit(next);
|
|
147
|
+
this.switchState = switchReducer(this.switchState, { type: 'native-reported', value: next });
|
|
148
|
+
|
|
149
|
+
const hostNode = readSwitchNode(node);
|
|
150
|
+
if (hostNode === null) return;
|
|
151
|
+
queueMicrotask(() => this.snapBackIfNeeded(hostNode));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private snapBackIfNeeded(node: ISymbioteNode): void {
|
|
155
|
+
const fabricValue = this.value === true;
|
|
156
|
+
if (!shouldSnapBack(this.switchState, fabricValue)) {
|
|
157
|
+
dlog(
|
|
158
|
+
`Switch snap-back no-op reported=${String(this.switchState.lastNativeReport)} value=${fabricValue}`,
|
|
159
|
+
);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
dlog(
|
|
164
|
+
`Switch ${this.platform.snapBackCommand} snap-back reported=${String(this.switchState.lastNativeReport)} value=${fabricValue}`,
|
|
165
|
+
);
|
|
166
|
+
whenCommitted(node, () => {
|
|
167
|
+
dispatchViewCommand(node, this.platform.snapBackCommand, [fabricValue]);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private inputProps(): Partial<ISwitchProps> {
|
|
172
|
+
const props: Partial<ISwitchProps> = {
|
|
173
|
+
value: this.value,
|
|
174
|
+
disabled: this.disabled,
|
|
175
|
+
trackColor: this.trackColor,
|
|
176
|
+
thumbColor: this.thumbColor,
|
|
177
|
+
ios_backgroundColor: this.ios_backgroundColor,
|
|
178
|
+
style: this.style,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
...props,
|
|
183
|
+
nativeID: this.nativeID,
|
|
184
|
+
testID: this.testID,
|
|
185
|
+
accessibilityLabel: this.accessibilityLabel,
|
|
186
|
+
accessibilityRole: this.accessibilityRole,
|
|
187
|
+
accessibilityState: this.accessibilityState,
|
|
188
|
+
accessibilityValue: this.accessibilityValue,
|
|
189
|
+
accessibilityHint: this.accessibilityHint,
|
|
190
|
+
accessible: this.accessible,
|
|
191
|
+
role: this.role,
|
|
192
|
+
'aria-label': this['aria-label'],
|
|
193
|
+
'aria-disabled': this['aria-disabled'],
|
|
194
|
+
'aria-checked': this['aria-checked'],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import '@angular/compiler';
|
|
2
|
+
import { Component } from '@angular/core';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { clearGlobalStyles, registerStyles } from '@symbiote-native/engine';
|
|
5
|
+
import { installFabric } from '@symbiote-native/test-utils';
|
|
6
|
+
|
|
7
|
+
import { mount, unmount } from '../../render';
|
|
8
|
+
import { Switch } from './index';
|
|
9
|
+
|
|
10
|
+
const ROOT_TAG = 902;
|
|
11
|
+
const fabric = installFabric();
|
|
12
|
+
|
|
13
|
+
let capturedHost: SwitchHost | undefined;
|
|
14
|
+
|
|
15
|
+
@Component({
|
|
16
|
+
selector: 'symbiote-switch-host',
|
|
17
|
+
standalone: true,
|
|
18
|
+
imports: [Switch],
|
|
19
|
+
template: `
|
|
20
|
+
<Switch [value]="value" (valueChange)="onValueChange($event)" (change)="onChange($event)">
|
|
21
|
+
</Switch>
|
|
22
|
+
`,
|
|
23
|
+
})
|
|
24
|
+
class SwitchHost {
|
|
25
|
+
value = false;
|
|
26
|
+
onValueChange = vi.fn((next: boolean) => {
|
|
27
|
+
this.value = next;
|
|
28
|
+
});
|
|
29
|
+
onChange = vi.fn();
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
// Captures the live component instance so the test can drive its signals after mount.
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
34
|
+
capturedHost = this;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
capturedHost = undefined;
|
|
40
|
+
fabric.reset();
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
unmount(ROOT_TAG);
|
|
44
|
+
clearGlobalStyles();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('Switch', () => {
|
|
48
|
+
it('commits a controlled Switch with the resolved iOS color props', async () => {
|
|
49
|
+
mount(ROOT_TAG, SwitchHost);
|
|
50
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
51
|
+
|
|
52
|
+
const node = fabric.find(n => n.viewName === 'Switch');
|
|
53
|
+
expect(node, 'Switch node committed').toBeDefined();
|
|
54
|
+
expect(node?.props).toMatchObject({
|
|
55
|
+
value: false,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('fires onValueChange and onChange when native reports a change', async () => {
|
|
60
|
+
mount(ROOT_TAG, SwitchHost);
|
|
61
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
62
|
+
|
|
63
|
+
const node = fabric.find(n => n.viewName === 'Switch');
|
|
64
|
+
expect(node).toBeDefined();
|
|
65
|
+
|
|
66
|
+
fabric.fireEvent(node?.instanceHandle, 'topChange', { value: true, eventCount: 1 });
|
|
67
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
68
|
+
|
|
69
|
+
const host = capturedHost;
|
|
70
|
+
expect(host?.onValueChange).toHaveBeenCalledWith(true);
|
|
71
|
+
expect(host?.onChange).toHaveBeenCalled();
|
|
72
|
+
expect(host?.value).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('resolves a class= on the Switch use site onto the real committed view, not the anchor', async () => {
|
|
76
|
+
registerStyles({ card: { backgroundColor: 'red' } });
|
|
77
|
+
|
|
78
|
+
mount(ROOT_TAG, SwitchClassHost);
|
|
79
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
80
|
+
|
|
81
|
+
const node = fabric.find(n => n.props.testID === 'switch-with-class');
|
|
82
|
+
expect(node?.props.backgroundColor).toBe('red');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
@Component({
|
|
87
|
+
selector: 'symbiote-switch-class-host',
|
|
88
|
+
standalone: true,
|
|
89
|
+
imports: [Switch],
|
|
90
|
+
template: `<Switch [testID]="'switch-with-class'" class="card"></Switch>`,
|
|
91
|
+
})
|
|
92
|
+
class SwitchClassHost {}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Regression test for the anchor/class bug: TextInput is its own
|
|
2
|
+
// ANCHOR_HOST_COMPONENTS entry — a class= on <TextInput> resolves onto TextInput's OWN anchor and
|
|
3
|
+
// needs its OWN anchorHostStyle merge (see text-input.ts's buildPassthrough), for BOTH the
|
|
4
|
+
// single-line and multiline host it renders through (`@if`/`@else` picks one at runtime). Mirrors
|
|
5
|
+
// pressable.test.ts's "resolves a class=" case.
|
|
6
|
+
import '@angular/compiler';
|
|
7
|
+
import { Component } from '@angular/core';
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
9
|
+
import { clearGlobalStyles, registerStyles } from '@symbiote-native/engine';
|
|
10
|
+
import { installFabric } from '@symbiote-native/test-utils';
|
|
11
|
+
|
|
12
|
+
import { mount, unmount } from '../render';
|
|
13
|
+
import { TextInput } from './text-input';
|
|
14
|
+
|
|
15
|
+
const ROOT_TAG = 917;
|
|
16
|
+
const fabric = installFabric();
|
|
17
|
+
|
|
18
|
+
@Component({
|
|
19
|
+
selector: 'symbiote-text-input-class-host',
|
|
20
|
+
standalone: true,
|
|
21
|
+
imports: [TextInput],
|
|
22
|
+
template: `
|
|
23
|
+
<TextInput [testID]="'single-line'" class="card" />
|
|
24
|
+
<TextInput [testID]="'multiline'" [multiline]="true" class="card" />
|
|
25
|
+
`,
|
|
26
|
+
})
|
|
27
|
+
class TextInputClassHost {}
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
fabric.reset();
|
|
31
|
+
registerStyles({ card: { backgroundColor: 'red' } });
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
unmount(ROOT_TAG);
|
|
35
|
+
clearGlobalStyles();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('TextInput anchor class= resolution', () => {
|
|
39
|
+
it('resolves a class= on the TextInput use site onto the real committed single-line host', async () => {
|
|
40
|
+
mount(ROOT_TAG, TextInputClassHost);
|
|
41
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
42
|
+
|
|
43
|
+
const node = fabric.find(n => n.props.testID === 'single-line');
|
|
44
|
+
expect(node?.props.backgroundColor).toBe('red');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('resolves a class= on the TextInput use site onto the real committed multiline host', async () => {
|
|
48
|
+
mount(ROOT_TAG, TextInputClassHost);
|
|
49
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
50
|
+
|
|
51
|
+
const node = fabric.find(n => n.props.testID === 'multiline');
|
|
52
|
+
expect(node?.props.backgroundColor).toBe('red');
|
|
53
|
+
});
|
|
54
|
+
});
|