@apexnative/navigation 1.0.0-alpha.6 → 1.0.0-alpha.8
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/ApexNavigation.podspec +2 -1
- package/CHANGELOG.md +15 -0
- package/android/CLAUDE.md +19 -10
- package/android/CORE.md +3 -2
- package/android/consumer-rules.pro +6 -0
- package/android/src/main/java/dev/apexnative/navigation/options/BottomTabOptions.kt +1 -1
- package/android/src/main/java/dev/apexnative/navigation/options/ButtonOptions.kt +1 -1
- package/android/src/main/java/dev/apexnative/navigation/options/LargeTitleOptions.kt +1 -1
- package/android/src/main/java/dev/apexnative/navigation/options/LayoutAnimation.kt +1 -1
- package/android/src/main/java/dev/apexnative/navigation/options/OptionKey.kt +18 -0
- package/android/src/main/java/dev/apexnative/navigation/options/OptionPaths.kt +91 -0
- package/android/src/main/java/dev/apexnative/navigation/options/SheetOptions.kt +7 -4
- package/android/src/main/java/dev/apexnative/navigation/options/TitleOptions.kt +2 -2
- package/android/src/main/java/dev/apexnative/navigation/options/TopBarAppearanceOptions.kt +1 -1
- package/android/src/main/java/dev/apexnative/navigation/options/TopBarOptions.kt +16 -7
- package/android/src/main/java/dev/apexnative/navigation/react/ContentHeights.kt +95 -0
- package/android/src/main/java/dev/apexnative/navigation/react/ContentMounts.kt +66 -0
- package/android/src/main/java/dev/apexnative/navigation/react/NavigationTurboModule.kt +4 -0
- package/android/src/main/java/dev/apexnative/navigation/react/OptionsCommands.kt +41 -3
- package/android/src/main/java/dev/apexnative/navigation/react/ReactView.kt +16 -1
- package/android/src/main/java/dev/apexnative/navigation/slots/SlotScreenView.kt +27 -7
- package/android/src/main/java/dev/apexnative/navigation/slots/SlotView.kt +12 -1
- package/android/src/main/java/dev/apexnative/navigation/utils/MaterialTheme.kt +5 -6
- package/android/src/main/java/dev/apexnative/navigation/utils/SystemAnimations.kt +36 -0
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/ModalSheet.kt +329 -55
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/ModalViews.kt +26 -5
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/SheetStops.kt +60 -2
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/sidemenu/SideMenuMotion.kt +8 -2
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/BackPreview.kt +32 -4
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackController.kt +46 -7
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackQueue.kt +15 -3
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackViews.kt +7 -4
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/fab/FabMotion.kt +142 -0
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/fab/FabPresenter.kt +215 -43
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/search/StackSearchPresenter.kt +25 -26
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/topbar/BarRowTransition.kt +3 -2
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/topbar/ButtonPlaces.kt +11 -5
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/topbar/TopBarPresenter.kt +86 -39
- package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/topbar/TopBarVisibility.kt +9 -2
- package/android/src/main/java/dev/apexnative/navigation/views/element/ElementTransitions.kt +124 -181
- package/android/src/main/java/dev/apexnative/navigation/views/element/TargetsWait.kt +8 -1
- package/android/src/main/java/dev/apexnative/navigation/views/element/TransitionLayer.kt +37 -112
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ElementPictures.kt +56 -3
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/FlightGeometry.kt +170 -153
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ImageMorph.kt +199 -0
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/SharedAnimatorFactory.kt +55 -45
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/{TextChangeAnimator.kt → TextMorph.kt} +79 -129
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ViewMorph.kt +108 -0
- package/android/src/main/java/dev/apexnative/navigation/views/stack/fab/FabCopy.kt +85 -0
- package/android/src/main/java/dev/apexnative/navigation/views/stack/fab/FabMenu.kt +13 -0
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/TitleBar.kt +5 -24
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/TopBar.kt +51 -34
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/BarButtonComponentCell.kt +6 -6
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/BarButtonView.kt +113 -0
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/BarMenu.kt +219 -0
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/ButtonBar.kt +121 -175
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/ButtonMenus.kt +34 -64
- package/android/src/main/java/dev/apexnative/navigation/views/stack/topbar/titlebar/ButtonRow.kt +216 -0
- package/android/src/main/jni/ANNContentHeights.cpp +82 -0
- package/android/src/main/res/drawable/apex_navigation_ic_arrow_right.xml +14 -0
- package/android/src/main/res/layout/apex_navigation_menu_header.xml +19 -0
- package/android/src/main/res/layout/apex_navigation_menu_item.xml +68 -0
- package/android/src/main/res/values/styles.xml +1 -1
- package/android/src/main/res/values-night/styles.xml +1 -1
- package/cli/doctor/checks/app.js +16 -1
- package/cli/project.js +4 -0
- package/cli/setup/index.js +5 -0
- package/cli/setup/steps/metro.js +46 -0
- package/docs-md/architecture/native-screens.md +4 -0
- package/docs-md/architecture/theme-and-context.md +131 -12
- package/docs-md/architecture/transitions.md +43 -4
- package/docs-md/flows/bottom-sheets.md +4 -2
- package/docs-md/fundamentals/screens-and-props.md +9 -1
- package/docs-md/guides/cli.md +3 -1
- package/docs-md/help/troubleshooting.md +1 -1
- package/docs-md/index.json +29 -1
- package/docs-md/screen-ui/back-and-gestures.md +3 -1
- package/docs-md/screen-ui/bar-buttons.md +1 -1
- package/docs-md/screen-ui/toolbar-and-fab.md +2 -0
- package/docs-md/start/installation.md +16 -1
- package/ios/Animations/ANNFrameDriver.h +55 -15
- package/ios/Animations/ANNFrameDriver.mm +214 -60
- package/ios/Animations/ANNTransitionAnimator.h +26 -5
- package/ios/Animations/ANNTransitionAnimator.mm +49 -3
- package/ios/Animations/ANNTransitionPlan.h +2 -2
- package/ios/Animations/ANNTransitionPlan.mm +10 -0
- package/ios/Animations/Elements/ANNElementFinder.h +2 -2
- package/ios/Animations/Elements/ANNElementFinder.mm +2 -2
- package/ios/Animations/Elements/ANNElementTransition.h +3 -3
- package/ios/Animations/Elements/ANNElementTransition.mm +2 -2
- package/ios/Animations/Elements/ANNSharedElementFlight.h +3 -3
- package/ios/Animations/Elements/ANNSharedElementFlight.mm +181 -43
- package/ios/Animations/Interpolators/ANNViewTracks.h +6 -5
- package/ios/Animations/Interpolators/ANNViewTracks.mm +51 -21
- package/ios/CLAUDE.md +19 -8
- package/ios/CORE.md +1 -1
- package/ios/Core/ANNAppDelegate.mm +0 -2
- package/ios/Core/ANNDeepLinkQueue.h +6 -5
- package/ios/Core/ANNDeepLinkQueue.mm +22 -10
- package/ios/Core/ANNSceneDelegate.mm +2 -2
- package/ios/Core/ANNUtils.h +7 -0
- package/ios/Core/ANNUtils.mm +10 -0
- package/ios/Core/ApexNavigation.mm +6 -2
- package/ios/Layouts/Overlay/ANNOverlayCoordinator.mm +1 -7
- package/ios/Layouts/Root/ANNRootCoordinator.mm +45 -15
- package/ios/Layouts/Screen/ANNComponentViewController.mm +4 -1
- package/ios/Layouts/Stack/ANNStackAnimatingDelegate.h +11 -2
- package/ios/Layouts/Stack/ANNStackAnimatingDelegate.mm +14 -7
- package/ios/Layouts/Stack/ANNStackController.h +8 -0
- package/ios/Layouts/Stack/ANNStackController.mm +153 -11
- package/ios/Layouts/Stack/ANNSwipePopInteraction.h +26 -0
- package/ios/Layouts/Stack/ANNSwipePopInteraction.mm +185 -0
- package/ios/Layouts/Stack/InteractivePopGestureDelegate.mm +28 -4
- package/ios/Layouts/Tabs/ANNTabsPreloadWindow.mm +2 -4
- package/ios/Options/ANNAnimationOptions.h +2 -1
- package/ios/Options/ANNAnimationOptions.mm +1 -1
- package/ios/Options/ANNOptions.h +7 -0
- package/ios/Options/ANNOptions.mm +45 -0
- package/ios/Options/ANNOptionsReader.mm +2 -4
- package/ios/Options/ANNStackPopAnimationOptions.h +13 -0
- package/ios/Options/ANNStackPopAnimationOptions.mm +11 -0
- package/ios/Options/Params/ColorParser.h +4 -3
- package/ios/Options/Params/ColorParser.mm +22 -4
- package/ios/React/ANNSurfaceHostingView.h +8 -0
- package/ios/React/ANNSurfaceHostingView.mm +28 -1
- package/ios/React/Slots/ANNSlotHost.mm +1 -3
- package/ios/React/Slots/ANNSlotScreenView.mm +8 -2
- package/ios/TurboModules/ANNTurboModule.mm +46 -0
- package/ios/cpp/react/renderer/components/ApexNavigationSpec/ANNSlotState.cpp +20 -0
- package/ios/cpp/react/renderer/components/ApexNavigationSpec/ANNSlotState.h +5 -14
- package/lib/module/ARCHITECTURE.md +9 -3
- package/lib/module/adapters/NativeANNTurboModule.js.map +1 -1
- package/lib/module/api/app/AppRegistry.js +14 -2
- package/lib/module/api/app/AppRegistry.js.map +1 -1
- package/lib/module/api/app/createNavigation.js +188 -66
- package/lib/module/api/app/createNavigation.js.map +1 -1
- package/lib/module/api/events/navigationEvents.js +6 -2
- package/lib/module/api/events/navigationEvents.js.map +1 -1
- package/lib/module/api/linking/linking.js +11 -0
- package/lib/module/api/linking/linking.js.map +1 -1
- package/lib/module/api/screens/defineScreen.js +45 -3
- package/lib/module/api/screens/defineScreen.js.map +1 -1
- package/lib/module/api/screens/nativeScreens.js +31 -6
- package/lib/module/api/screens/nativeScreens.js.map +1 -1
- package/lib/module/api/screens/registerScreens.js +193 -35
- package/lib/module/api/screens/registerScreens.js.map +1 -1
- package/lib/module/api/theme/theme.js +5 -0
- package/lib/module/api/theme/theme.js.map +1 -1
- package/lib/module/engine/commands.js +21 -1
- package/lib/module/engine/commands.js.map +1 -1
- package/lib/module/engine/layout.js +7 -2
- package/lib/module/engine/layout.js.map +1 -1
- package/lib/module/engine/nativeScreens.js +9 -0
- package/lib/module/engine/nativeScreens.js.map +1 -1
- package/lib/module/engine/options.js +5 -4
- package/lib/module/engine/options.js.map +1 -1
- package/lib/module/engine/optionsChange.js +102 -0
- package/lib/module/engine/optionsChange.js.map +1 -0
- package/lib/module/engine/refresh.js +85 -0
- package/lib/module/engine/refresh.js.map +1 -0
- package/lib/module/engine/rememberedOptions.js +60 -0
- package/lib/module/engine/rememberedOptions.js.map +1 -1
- package/lib/module/engine/screens.js +26 -0
- package/lib/module/engine/screens.js.map +1 -1
- package/lib/typescript/adapters/NativeANNTurboModule.d.ts +7 -0
- package/lib/typescript/adapters/NativeANNTurboModule.d.ts.map +1 -1
- package/lib/typescript/api/app/AppRegistry.d.ts.map +1 -1
- package/lib/typescript/api/app/createNavigation.d.ts +5 -0
- package/lib/typescript/api/app/createNavigation.d.ts.map +1 -1
- package/lib/typescript/api/events/navigationEvents.d.ts +2 -2
- package/lib/typescript/api/events/navigationEvents.d.ts.map +1 -1
- package/lib/typescript/api/index.d.ts +1 -1
- package/lib/typescript/api/index.d.ts.map +1 -1
- package/lib/typescript/api/linking/linking.d.ts +8 -0
- package/lib/typescript/api/linking/linking.d.ts.map +1 -1
- package/lib/typescript/api/screens/defineScreen.d.ts +23 -4
- package/lib/typescript/api/screens/defineScreen.d.ts.map +1 -1
- package/lib/typescript/api/screens/nativeScreens.d.ts +8 -1
- package/lib/typescript/api/screens/nativeScreens.d.ts.map +1 -1
- package/lib/typescript/api/screens/registerScreens.d.ts.map +1 -1
- package/lib/typescript/api/theme/theme.d.ts +2 -0
- package/lib/typescript/api/theme/theme.d.ts.map +1 -1
- package/lib/typescript/engine/commands.d.ts +5 -0
- package/lib/typescript/engine/commands.d.ts.map +1 -1
- package/lib/typescript/engine/layout.d.ts.map +1 -1
- package/lib/typescript/engine/nativeScreens.d.ts +5 -0
- package/lib/typescript/engine/nativeScreens.d.ts.map +1 -1
- package/lib/typescript/engine/optionsChange.d.ts +28 -0
- package/lib/typescript/engine/optionsChange.d.ts.map +1 -0
- package/lib/typescript/engine/refresh.d.ts +35 -0
- package/lib/typescript/engine/refresh.d.ts.map +1 -0
- package/lib/typescript/engine/rememberedOptions.d.ts +13 -0
- package/lib/typescript/engine/rememberedOptions.d.ts.map +1 -1
- package/lib/typescript/engine/screens.d.ts +7 -0
- package/lib/typescript/engine/screens.d.ts.map +1 -1
- package/lib/typescript/interfaces/ComponentEvents.d.ts +2 -2
- package/lib/typescript/interfaces/options/animations.d.ts +40 -15
- package/lib/typescript/interfaces/options/animations.d.ts.map +1 -1
- package/lib/typescript/interfaces/options/bottomTabs.d.ts +2 -2
- package/lib/typescript/interfaces/options/buttons.d.ts +2 -2
- package/lib/typescript/interfaces/options/modals.d.ts +6 -7
- package/lib/typescript/interfaces/options/modals.d.ts.map +1 -1
- package/lib/typescript/interfaces/options/stack.d.ts +8 -3
- package/lib/typescript/interfaces/options/stack.d.ts.map +1 -1
- package/lib/typescript/interfaces/options/topBar.d.ts +14 -0
- package/lib/typescript/interfaces/options/topBar.d.ts.map +1 -1
- package/metro/acceptPlugin.js +57 -0
- package/metro/babelTransformer.js +45 -0
- package/metro/index.js +36 -0
- package/package.json +3 -1
- package/src/ARCHITECTURE.md +9 -3
- package/src/adapters/NativeANNTurboModule.ts +7 -0
- package/src/api/app/AppRegistry.ts +16 -2
- package/src/api/app/createNavigation.ts +198 -66
- package/src/api/events/navigationEvents.ts +9 -3
- package/src/api/index.ts +1 -0
- package/src/api/linking/linking.ts +22 -1
- package/src/api/screens/defineScreen.ts +49 -5
- package/src/api/screens/nativeScreens.ts +40 -4
- package/src/api/screens/registerScreens.tsx +185 -42
- package/src/api/theme/theme.ts +5 -0
- package/src/engine/commands.ts +21 -0
- package/src/engine/layout.ts +11 -2
- package/src/engine/nativeScreens.ts +10 -1
- package/src/engine/options.ts +6 -8
- package/src/engine/optionsChange.ts +107 -0
- package/src/engine/refresh.ts +97 -0
- package/src/engine/rememberedOptions.ts +70 -0
- package/src/engine/screens.tsx +24 -0
- package/src/interfaces/ComponentEvents.ts +2 -2
- package/src/interfaces/options/animations.ts +40 -15
- package/src/interfaces/options/bottomTabs.ts +2 -2
- package/src/interfaces/options/buttons.ts +2 -2
- package/src/interfaces/options/modals.ts +6 -7
- package/src/interfaces/options/stack.ts +8 -3
- package/src/interfaces/options/topBar.ts +14 -0
- package/android/src/main/java/dev/apexnative/navigation/views/element/ElementStub.kt +0 -31
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ImageMatrixAnimator.kt +0 -134
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/PlainViewAnimator.kt +0 -78
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/PropertyAnimatorCreator.kt +0 -33
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ReactImageAnimator.kt +0 -57
- package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ViewChangeAnimator.kt +0 -146
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { redefined, resetOnEdit } from '../../engine/refresh';
|
|
1
3
|
import type { ScreenArrangement } from './arrangement';
|
|
2
4
|
import type { ScreenOptionsInput } from './defineScreen';
|
|
3
5
|
|
|
@@ -30,7 +32,9 @@ export interface NativeScreenDefinition<Props extends object> {
|
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* A native screen for `screens`: commands and layouts name it like any other screen, and its props go to the native
|
|
33
|
-
* creator. `nativeName` is the name it is registered under natively (`ApexNavigation.registerNativeScreen`).
|
|
35
|
+
* creator. `nativeName` is the name it is registered under natively (`ApexNavigation.registerNativeScreen`). It is a
|
|
36
|
+
* component that runs `useProps`, so a file that exports only its screens updates by Fast Refresh, the hook and the
|
|
37
|
+
* options too.
|
|
34
38
|
*
|
|
35
39
|
* @example
|
|
36
40
|
* const Settings = nativeScreen('Settings', {
|
|
@@ -49,10 +53,42 @@ export function nativeScreen<Props extends object = {}>(
|
|
|
49
53
|
nativeName: string,
|
|
50
54
|
definition: NativeScreenDefinition<Props> = {}
|
|
51
55
|
): NativeScreen<Props> {
|
|
52
|
-
const { options, useProps, arrangement } = definition;
|
|
53
|
-
|
|
56
|
+
const { options, useProps = noProps, arrangement } = definition;
|
|
57
|
+
// A component that runs the hook, so that a file exporting only its screens stays a boundary of Fast Refresh: React
|
|
58
|
+
// Refresh puts the new version in place, with the edited hook.
|
|
59
|
+
function NativeScreen({ props, onProps }: NativeScreenHookProps<Props>) {
|
|
60
|
+
const result = useProps(props);
|
|
61
|
+
// After each render React committed, so the native side never shows what the app did not.
|
|
62
|
+
useEffect(() => onProps(result));
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const screen = Object.assign(NativeScreen, {
|
|
66
|
+
[NATIVE_SCREEN]: true as const,
|
|
67
|
+
nativeName,
|
|
68
|
+
options,
|
|
69
|
+
useProps: definition.useProps,
|
|
70
|
+
arrangement,
|
|
71
|
+
});
|
|
72
|
+
// The hook is the app's and may have other hooks after an edit: its new version mounts anew.
|
|
73
|
+
resetOnEdit(screen);
|
|
74
|
+
redefined(screen);
|
|
75
|
+
return screen;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function noProps(): object {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What the component of a native screen renders with: the props of the command, and where the hook's result goes. */
|
|
83
|
+
export interface NativeScreenHookProps<Props> {
|
|
84
|
+
props: Props;
|
|
85
|
+
onProps(result: object): void;
|
|
54
86
|
}
|
|
55
87
|
|
|
56
88
|
export function isNativeScreen(value: unknown): value is NativeScreen<any> {
|
|
57
|
-
return
|
|
89
|
+
return (
|
|
90
|
+
(typeof value === 'function' || typeof value === 'object') &&
|
|
91
|
+
value !== null &&
|
|
92
|
+
NATIVE_SCREEN in value
|
|
93
|
+
);
|
|
58
94
|
}
|
|
@@ -6,32 +6,39 @@ import React, {
|
|
|
6
6
|
lazy,
|
|
7
7
|
type ReactNode,
|
|
8
8
|
Suspense,
|
|
9
|
-
useEffect,
|
|
10
9
|
useMemo,
|
|
11
10
|
useState,
|
|
12
11
|
} from 'react';
|
|
13
|
-
import { Platform, StyleSheet } from 'react-native';
|
|
12
|
+
import { DevSettings, Platform, StyleSheet } from 'react-native';
|
|
14
13
|
import ANNTurboModule from '../../adapters/NativeANNTurboModule';
|
|
15
14
|
import type { NativeControllerProps } from '../../engine/nativeScreens';
|
|
16
15
|
import { isButtonRoot } from '../../engine/props';
|
|
17
16
|
import {
|
|
18
17
|
checkArrangements,
|
|
19
|
-
type EngineArrangement,
|
|
20
18
|
onScreenUnmounted,
|
|
21
19
|
registerScreen as registerEngineScreen,
|
|
22
20
|
type ScreenRootProps,
|
|
21
|
+
shownScreens,
|
|
23
22
|
} from '../../engine/screens';
|
|
24
23
|
import { screenUnmounted } from '../events/screenLifecycle';
|
|
25
24
|
import { mergeOptions } from '../../engine/mergeOptions';
|
|
26
25
|
import { preparedPadding } from '../../engine/slots';
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
26
|
+
import { clearOptions, mergeOptions as sendMergeOptions } from '../../engine/commands';
|
|
27
|
+
import { changeOverOwn, optionsChange } from '../../engine/optionsChange';
|
|
28
|
+
import { notedScreens, ownOptionsOf } from '../../engine/rememberedOptions';
|
|
29
|
+
import { openNativeScreens } from '../../engine/nativeScreens';
|
|
30
|
+
import { placeOf } from '../../engine/places';
|
|
31
|
+
import { propsOf } from '../../engine/props';
|
|
32
|
+
import { familyOf, newestType, onRedefined } from '../../engine/refresh';
|
|
29
33
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
buildScreenOptions,
|
|
35
|
+
definitionOf,
|
|
36
|
+
ownDefinitionOf,
|
|
37
|
+
type ScreenDefinition,
|
|
38
|
+
type ScreenOptionsInput,
|
|
39
|
+
} from './defineScreen';
|
|
40
|
+
import { isNativeScreen, type NativeScreen, type NativeScreenHookProps } from './nativeScreens';
|
|
41
|
+
import { type Arrangement, isArrangement, toEngineArrangement } from './arrangement';
|
|
35
42
|
import { type ErrorFallbackProps, ScreenBoundary } from './ScreenBoundary';
|
|
36
43
|
import ANNSafeAreaView from '../safeArea/ANNSafeAreaViewNativeComponent';
|
|
37
44
|
|
|
@@ -98,6 +105,125 @@ export interface ScreenSet {
|
|
|
98
105
|
// The root of a screen tells when it unmounts: what the screen left behind goes.
|
|
99
106
|
onScreenUnmounted(screenUnmounted);
|
|
100
107
|
|
|
108
|
+
// The screens of defineScreen by name, in development: what `screens` gives (a lazy screen's module once loaded) and
|
|
109
|
+
// the options of its group.
|
|
110
|
+
const editable = new Map<
|
|
111
|
+
string,
|
|
112
|
+
{ screen: () => unknown; groupOptions: ScreenOptionsInput<object> | undefined }
|
|
113
|
+
>();
|
|
114
|
+
|
|
115
|
+
onRedefined(applyEdit);
|
|
116
|
+
|
|
117
|
+
// Fast Refresh ran the module of a screen again: the screens of it that show take what the edit changed in their
|
|
118
|
+
// options, as a command would have shown them. The family's newest is still the version before the edit here, as React
|
|
119
|
+
// Refresh moves it on only after the update.
|
|
120
|
+
function applyEdit(next: object) {
|
|
121
|
+
const family = familyOf(next);
|
|
122
|
+
const edited = ownDefinitionOf(next) ?? (isNativeScreen(next) ? next : undefined);
|
|
123
|
+
if (!family || !edited) return;
|
|
124
|
+
for (const [name, { screen, groupOptions }] of editable) {
|
|
125
|
+
const current = screen();
|
|
126
|
+
if (current === undefined || familyOf(current) !== family) continue;
|
|
127
|
+
const native = isNativeScreen(current);
|
|
128
|
+
const before = native ? newestType(current) : definitionOf(current);
|
|
129
|
+
// The screen as it was registered: its own module running, nothing edited yet.
|
|
130
|
+
if (before === edited) continue;
|
|
131
|
+
// What a native screen is made of goes to the native side when it is registered and shown: a change of it starts
|
|
132
|
+
// the app again.
|
|
133
|
+
if (native && isNativeScreen(edited) && madeOtherwise(newestType(current), edited)) {
|
|
134
|
+
DevSettings.reload('[navigation] A native screen changed its name or its useProps');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
applyChange(
|
|
138
|
+
name,
|
|
139
|
+
native,
|
|
140
|
+
{ group: groupOptions, definition: before },
|
|
141
|
+
{ group: groupOptions, definition: edited }
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The options a screen is shown with: those of its group, and those of its definition over them. */
|
|
147
|
+
interface ShownOptions {
|
|
148
|
+
group: ScreenOptionsInput<object> | undefined;
|
|
149
|
+
definition: { options?: ScreenOptionsInput<any> } | undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// What an edit changed in a screen's options goes to every screen of it the native side has, a screen React hasn't
|
|
153
|
+
// mounted yet too (a tab not selected yet), as a command would have shown it; only where the screen still has what
|
|
154
|
+
// the definition before gave.
|
|
155
|
+
function applyChange(name: string, native: boolean, before: ShownOptions, after: ShownOptions) {
|
|
156
|
+
const shown = native
|
|
157
|
+
? openNativeScreens(name)
|
|
158
|
+
: [...new Set([...shownScreens(name), ...notedScreens(name).filter(isPlaced)])].map((id) => ({
|
|
159
|
+
id,
|
|
160
|
+
props: propsOf(id),
|
|
161
|
+
}));
|
|
162
|
+
for (const { id, props } of shown) {
|
|
163
|
+
const options = ({ group, definition }: ShownOptions) =>
|
|
164
|
+
mergeOptions(
|
|
165
|
+
buildScreenOptions(group, props),
|
|
166
|
+
buildScreenOptions(definition?.options, props)
|
|
167
|
+
);
|
|
168
|
+
const shownWith = options(before);
|
|
169
|
+
const change = optionsChange(shownWith, options(after));
|
|
170
|
+
const { merge, removed } = changeOverOwn(change, shownWith, ownOptionsOf(id) ?? shownWith);
|
|
171
|
+
if (removed.length > 0) clearOptions(id, removed);
|
|
172
|
+
if (merge) sendMergeOptions(id, merge);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The screens map registered again (Fast Refresh ran the module of the app): a screen written in the map itself, a
|
|
177
|
+
// definition no module exports, has no family to tell its edit, so its definition before and after are compared here.
|
|
178
|
+
// The options of its group too: a group is written in the app's module, and an edit of them leaves the screen as it was.
|
|
179
|
+
function applyRegisteredAgain(
|
|
180
|
+
name: string,
|
|
181
|
+
entry: unknown,
|
|
182
|
+
group: ScreenOptionsInput<object> | undefined
|
|
183
|
+
) {
|
|
184
|
+
const previous = editable.get(name);
|
|
185
|
+
const before = previous?.screen();
|
|
186
|
+
if (before === undefined) return;
|
|
187
|
+
if (before === entry) {
|
|
188
|
+
if (previous!.groupOptions === group) return;
|
|
189
|
+
const native = isNativeScreen(entry);
|
|
190
|
+
const definition = native ? newestType(entry) : definitionOf(entry);
|
|
191
|
+
applyChange(name, native, { group: previous!.groupOptions, definition }, { group, definition });
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (isNativeScreen(before) && isNativeScreen(entry)) {
|
|
195
|
+
if (madeOtherwise(newestType(before), entry)) {
|
|
196
|
+
DevSettings.reload('[navigation] A native screen changed its name or its useProps');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
applyChange(
|
|
200
|
+
name,
|
|
201
|
+
true,
|
|
202
|
+
{ group: previous!.groupOptions, definition: newestType(before) },
|
|
203
|
+
{ group, definition: entry }
|
|
204
|
+
);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const was = definitionOf(before);
|
|
208
|
+
const now = definitionOf(entry);
|
|
209
|
+
if (!was && !now && previous!.groupOptions === group) return;
|
|
210
|
+
applyChange(
|
|
211
|
+
name,
|
|
212
|
+
false,
|
|
213
|
+
{ group: previous!.groupOptions, definition: was },
|
|
214
|
+
{ group, definition: now }
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// A screen the engine knows the place of: one whose command failed after its layout was built has none.
|
|
219
|
+
function isPlaced(id: string): boolean {
|
|
220
|
+
return placeOf(id) !== undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function madeOtherwise(before: NativeScreen<any>, after: NativeScreen<any>): boolean {
|
|
224
|
+
return before.nativeName !== after.nativeName || !before.useProps !== !after.useProps;
|
|
225
|
+
}
|
|
226
|
+
|
|
101
227
|
export function registerScreens(sets: ScreenSet[], wrapper: ScreenWrapper = {}) {
|
|
102
228
|
// The screens of every set are in one namespace: a command names a screen without its group.
|
|
103
229
|
const sources = new Map<string, string>();
|
|
@@ -131,21 +257,38 @@ function registerScreen(
|
|
|
131
257
|
return;
|
|
132
258
|
}
|
|
133
259
|
if (isNativeScreen(entry)) {
|
|
260
|
+
// Read on every show, the newest after Fast Refresh, as for a screen of defineScreen.
|
|
261
|
+
const screen = () => newestType(entry);
|
|
262
|
+
if (__DEV__) {
|
|
263
|
+
applyRegisteredAgain(name, entry, groupOptions);
|
|
264
|
+
editable.set(name, { screen: () => entry, groupOptions });
|
|
265
|
+
}
|
|
134
266
|
registerEngineScreen(name, {
|
|
135
267
|
nativeName: entry.nativeName,
|
|
136
268
|
options: (props) =>
|
|
137
269
|
mergeOptions(
|
|
138
270
|
buildScreenOptions(groupOptions, props),
|
|
139
|
-
buildScreenOptions(
|
|
271
|
+
buildScreenOptions(screen().options, props)
|
|
140
272
|
),
|
|
141
|
-
controller: entry.useProps && wrapNativeScreen(name, entry
|
|
142
|
-
arrangement:
|
|
273
|
+
controller: entry.useProps && wrapNativeScreen(name, entry, wrapper),
|
|
274
|
+
arrangement: () => {
|
|
275
|
+
const arrangement = screen().arrangement;
|
|
276
|
+
return arrangement && toEngineArrangement(name, arrangement);
|
|
277
|
+
},
|
|
143
278
|
});
|
|
144
279
|
return;
|
|
145
280
|
}
|
|
146
281
|
// React.memo and forwardRef components are objects, so the kind of entry is told by its keys.
|
|
147
282
|
if (isObject(entry) && 'load' in entry) {
|
|
148
283
|
const screen = lazyScreen(entry.load);
|
|
284
|
+
if (__DEV__) {
|
|
285
|
+
// A lazy screen registered again loads its module on its next show: until then the one loaded before stands for
|
|
286
|
+
// it, so the screens of it that show take an edit of their group's options, and of their module, as before.
|
|
287
|
+
const before = editable.get(name)?.screen();
|
|
288
|
+
const loaded = () => screen.loaded() ?? before;
|
|
289
|
+
applyRegisteredAgain(name, loaded(), groupOptions);
|
|
290
|
+
editable.set(name, { screen: loaded, groupOptions });
|
|
291
|
+
}
|
|
149
292
|
registerEngineScreen(name, {
|
|
150
293
|
component: () => wrapScreen(name, screen.component, wrapper),
|
|
151
294
|
// A command loads the screen before it reads its options.
|
|
@@ -164,32 +307,34 @@ function registerScreen(
|
|
|
164
307
|
});
|
|
165
308
|
return;
|
|
166
309
|
}
|
|
167
|
-
|
|
310
|
+
// Read on every show: after Fast Refresh a screen of defineScreen gives its new options, key and pair.
|
|
311
|
+
const definition = () => toDefinition(entry);
|
|
312
|
+
if (__DEV__) {
|
|
313
|
+
applyRegisteredAgain(name, entry, groupOptions);
|
|
314
|
+
editable.set(name, { screen: () => entry, groupOptions });
|
|
315
|
+
}
|
|
168
316
|
registerEngineScreen(name, {
|
|
169
|
-
component: () => wrapScreen(name, definition.component, wrapper),
|
|
317
|
+
component: () => wrapScreen(name, definition().component, wrapper),
|
|
170
318
|
options: (props) =>
|
|
171
319
|
mergeOptions(
|
|
172
320
|
buildScreenOptions(groupOptions, props),
|
|
173
|
-
buildScreenOptions(definition.options, props)
|
|
321
|
+
buildScreenOptions(definition().options, props)
|
|
174
322
|
),
|
|
175
|
-
key:
|
|
323
|
+
key: (props) => definition().key?.(props),
|
|
176
324
|
ownRoot,
|
|
177
|
-
arrangement:
|
|
325
|
+
arrangement: () => {
|
|
326
|
+
const arrangement = definition().arrangement;
|
|
327
|
+
return arrangement && toEngineArrangement(name, arrangement);
|
|
328
|
+
},
|
|
178
329
|
});
|
|
179
330
|
}
|
|
180
331
|
|
|
181
|
-
// The pair of a screen whose `arrangement` is known at registration: checked and filled in once.
|
|
182
|
-
function pairOf(
|
|
183
|
-
name: string,
|
|
184
|
-
arrangement: ScreenArrangement<any> | undefined
|
|
185
|
-
): (() => EngineArrangement) | undefined {
|
|
186
|
-
if (!arrangement) return undefined;
|
|
187
|
-
const pair = toEngineArrangement(name, arrangement);
|
|
188
|
-
return () => pair;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
332
|
function toDefinition(value: ScreenComponent | ScreenDefinition): ScreenDefinition {
|
|
192
|
-
|
|
333
|
+
// A screen of defineScreen renders as itself: React Refresh knows it by its module's export, and the version of the
|
|
334
|
+
// newest definition renders in its place.
|
|
335
|
+
const defined = definitionOf(value);
|
|
336
|
+
if (defined) return { ...defined, component: value as ScreenComponent };
|
|
337
|
+
return isObject(value) && 'component' in value ? value : { component: value as ScreenComponent };
|
|
193
338
|
}
|
|
194
339
|
|
|
195
340
|
/**
|
|
@@ -198,15 +343,17 @@ function toDefinition(value: ScreenComponent | ScreenDefinition): ScreenDefiniti
|
|
|
198
343
|
* screen) waits for it in Suspense.
|
|
199
344
|
*/
|
|
200
345
|
function lazyScreen(loadModule: () => ScreenModule | PromiseLike<ScreenModule>) {
|
|
201
|
-
|
|
346
|
+
// The screen the module gives; its definition is read from it each time, the newest after Fast Refresh.
|
|
347
|
+
let loaded: ScreenComponent | ScreenDefinition | undefined;
|
|
202
348
|
let loading: Promise<void> | undefined;
|
|
349
|
+
const definition = () => (loaded ? toDefinition(loaded) : undefined);
|
|
203
350
|
const load = (): Promise<void> | undefined => {
|
|
204
|
-
if (
|
|
351
|
+
if (loaded) return undefined;
|
|
205
352
|
if (!loading) {
|
|
206
353
|
loading = Promise.resolve()
|
|
207
354
|
.then(loadModule)
|
|
208
355
|
.then((module) => {
|
|
209
|
-
|
|
356
|
+
loaded = unwrapModule(module);
|
|
210
357
|
});
|
|
211
358
|
loading.catch(() => {
|
|
212
359
|
loading = undefined;
|
|
@@ -216,14 +363,14 @@ function lazyScreen(loadModule: () => ScreenModule | PromiseLike<ScreenModule>)
|
|
|
216
363
|
};
|
|
217
364
|
const Loaded = lazy(async () => {
|
|
218
365
|
await load();
|
|
219
|
-
return { default: definition!.component };
|
|
366
|
+
return { default: definition()!.component };
|
|
220
367
|
});
|
|
221
368
|
function LazyScreen(props: object) {
|
|
222
369
|
// The same component for the life of the view, so that the load doesn't mount it again.
|
|
223
|
-
const [Screen] = useState(() => definition?.component ?? Loaded);
|
|
370
|
+
const [Screen] = useState(() => definition()?.component ?? Loaded);
|
|
224
371
|
return <Screen {...props} />;
|
|
225
372
|
}
|
|
226
|
-
return { load, definition: () =>
|
|
373
|
+
return { load, definition, loaded: () => loaded, component: LazyScreen };
|
|
227
374
|
}
|
|
228
375
|
|
|
229
376
|
function unwrapModule(loaded: ScreenModule): ScreenComponent | ScreenDefinition {
|
|
@@ -297,15 +444,11 @@ function wrapScreen(name: string, Screen: ScreenComponent, wrapper: ScreenWrappe
|
|
|
297
444
|
*/
|
|
298
445
|
function wrapNativeScreen(
|
|
299
446
|
name: string,
|
|
300
|
-
|
|
447
|
+
entry: NativeScreen<any>,
|
|
301
448
|
{ provider: Provider, onError }: ScreenWrapper
|
|
302
449
|
): ComponentType<NativeControllerProps> {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// After each render React committed, so the native side never shows what the app did not.
|
|
306
|
-
useEffect(() => onProps(result));
|
|
307
|
-
return null;
|
|
308
|
-
}
|
|
450
|
+
// The screen's own component runs the hook: Fast Refresh puts a new version of it in place.
|
|
451
|
+
const Hook = entry as unknown as ComponentType<NativeScreenHookProps<object>>;
|
|
309
452
|
function NativeScreenProps({
|
|
310
453
|
componentId,
|
|
311
454
|
props,
|
package/src/api/theme/theme.ts
CHANGED
|
@@ -135,6 +135,11 @@ export function setTheme(next: NavigationTheme) {
|
|
|
135
135
|
listeners.forEach((listener) => listener());
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
/** The direction of the app now: the config's, or the one `setDirection` gave since. */
|
|
139
|
+
export function getDirection(): NavigationDirection | undefined {
|
|
140
|
+
return direction;
|
|
141
|
+
}
|
|
142
|
+
|
|
138
143
|
/** Changes the direction of the app: the bars, the transitions and the swipe back follow at once. */
|
|
139
144
|
export function setDirection(next: NavigationDirection) {
|
|
140
145
|
direction = next;
|
package/src/engine/commands.ts
CHANGED
|
@@ -13,6 +13,8 @@ import { columnOf, forgetPlace, layoutsOf, notePlaces, placeOf, stackOfColumn }
|
|
|
13
13
|
import { forgetProps } from './props';
|
|
14
14
|
import {
|
|
15
15
|
forgetMergedOptions,
|
|
16
|
+
forgetMergedPaths,
|
|
17
|
+
noteMergedOwnOptions,
|
|
16
18
|
rememberMergedOptions,
|
|
17
19
|
rootGoesOut,
|
|
18
20
|
sentRoot,
|
|
@@ -144,6 +146,7 @@ export function mergeOptions(componentId: string, options: Options): void {
|
|
|
144
146
|
const nativeOptions = toNativeOptions(options, componentId);
|
|
145
147
|
const send = () => {
|
|
146
148
|
rememberMergedOptions(componentId, options);
|
|
149
|
+
noteMergedOwnOptions(componentId, options);
|
|
147
150
|
native.mergeOptions(componentId, nativeOptions);
|
|
148
151
|
};
|
|
149
152
|
const prepared =
|
|
@@ -152,6 +155,24 @@ export function mergeOptions(componentId: string, options: Options): void {
|
|
|
152
155
|
else heldMerges.push({ id: componentId, after: shows, send });
|
|
153
156
|
}
|
|
154
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Takes the options at the paths, such as `['topBar', 'subtitle']`, out of the own options of a node, so it shows what
|
|
160
|
+
* the layouts around it and the defaults give there (Fast Refresh, development). It waits for the shows as a merge does.
|
|
161
|
+
*/
|
|
162
|
+
export function clearOptions(componentId: string, paths: readonly string[][]): void {
|
|
163
|
+
const send = () => {
|
|
164
|
+
forgetMergedPaths(componentId, paths);
|
|
165
|
+
native.clearOptions(
|
|
166
|
+
componentId,
|
|
167
|
+
paths.map((path) => path.join('.'))
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
const prepared =
|
|
171
|
+
preparedScreens.has(componentId) && !heldMerges.some(({ id }) => id === componentId);
|
|
172
|
+
if (waitingShows.size === 0 || prepared) send();
|
|
173
|
+
else heldMerges.push({ id: componentId, after: shows, send });
|
|
174
|
+
}
|
|
175
|
+
|
|
155
176
|
// Runs a show command; the function `run` gets lets the mergeOptions made after the show go, once it went out. It is
|
|
156
177
|
// called again when the command ends, so a command that fails before it goes out lets them go too.
|
|
157
178
|
function show<Result>(run: (goneOut: () => void) => Promise<Result>): Promise<Result> {
|
package/src/engine/layout.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { nextId } from './ids';
|
|
|
14
14
|
import { showNativeScreen } from './nativeScreens';
|
|
15
15
|
import { toNativeOptions } from './options';
|
|
16
16
|
import { setProps } from './props';
|
|
17
|
+
import { noteOwnOptions } from './rememberedOptions';
|
|
17
18
|
import { getStartInfo } from './native';
|
|
18
19
|
import { noteAlone } from './places';
|
|
19
20
|
import {
|
|
@@ -103,6 +104,13 @@ function screen(component: LayoutComponent, inPair = false, keyed = !inPair): La
|
|
|
103
104
|
if (nativeName) {
|
|
104
105
|
// A native screen: its props go to the native side as data, its own options over those of the show.
|
|
105
106
|
const options = takeButtonHandlers(id, component.options ?? {});
|
|
107
|
+
if (__DEV__) {
|
|
108
|
+
noteOwnOptions(
|
|
109
|
+
id,
|
|
110
|
+
name,
|
|
111
|
+
mergeOptions(screenOptions(name, props ?? {}), component.options ?? {})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
106
114
|
const node = external({
|
|
107
115
|
id,
|
|
108
116
|
name: nativeName,
|
|
@@ -113,8 +121,9 @@ function screen(component: LayoutComponent, inPair = false, keyed = !inPair): La
|
|
|
113
121
|
}
|
|
114
122
|
// The screen's own options under those of the show (a command has them there already: merging again changes
|
|
115
123
|
// nothing).
|
|
116
|
-
const own = screenOptions(name, props ?? {});
|
|
117
|
-
|
|
124
|
+
const own = mergeOptions(screenOptions(name, props ?? {}), component.options ?? {});
|
|
125
|
+
noteOwnOptions(id, name, own);
|
|
126
|
+
const options = takeButtonHandlers(id, own);
|
|
118
127
|
const key = keyed ? screenKey(name, props ?? {}) : undefined;
|
|
119
128
|
setProps(id, props);
|
|
120
129
|
return {
|
|
@@ -38,6 +38,8 @@ interface NativeProps {
|
|
|
38
38
|
interface OpenScreen {
|
|
39
39
|
id: string;
|
|
40
40
|
name: string;
|
|
41
|
+
/** The props the command gave, as they are. */
|
|
42
|
+
given: object;
|
|
41
43
|
props: NativeProps;
|
|
42
44
|
/** The data the native side has, and the names of the functions; none before the command sends the screen. */
|
|
43
45
|
sent?: { data: Map<string, string>; functions: string };
|
|
@@ -78,7 +80,7 @@ export const nativeScreenHooks = {
|
|
|
78
80
|
* screen with `useProps` starts its hook, and its props go in once the hook has returned (`whenNativeScreensReady`).
|
|
79
81
|
*/
|
|
80
82
|
export function showNativeScreen(node: LayoutNode, name: string, props: object): void {
|
|
81
|
-
const screen: OpenScreen = { id: node.id, name, props: toNativeProps(props) };
|
|
83
|
+
const screen: OpenScreen = { id: node.id, name, given: props, props: toNativeProps(props) };
|
|
82
84
|
const Controller = nativeScreenController(name);
|
|
83
85
|
if (Controller) {
|
|
84
86
|
screen.first = deferred();
|
|
@@ -135,6 +137,13 @@ export function callNativeScreenFunction(id: string, name: string, args: unknown
|
|
|
135
137
|
return fn(...args);
|
|
136
138
|
}
|
|
137
139
|
|
|
140
|
+
/** The native screens with the name that are open, each with the props its command gave. */
|
|
141
|
+
export function openNativeScreens(name: string): { id: string; props: object }[] {
|
|
142
|
+
return [...screens.values()]
|
|
143
|
+
.filter((screen) => screen.name === name)
|
|
144
|
+
.map((screen) => ({ id: screen.id, props: screen.given }));
|
|
145
|
+
}
|
|
146
|
+
|
|
138
147
|
/** The native screen with the id, for the navigation of its calls. */
|
|
139
148
|
export function nativeScreenInfo(id: string): { id: string; name: string } | undefined {
|
|
140
149
|
const screen = screens.get(id);
|
package/src/engine/options.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Image, Platform, processColor } from 'react-native';
|
|
2
2
|
import type { ColorValue, ImageSourcePropType } from 'react-native';
|
|
3
3
|
import { nextId } from './ids';
|
|
4
4
|
import { rememberButtonRoot, rememberOptionsComponent, setProps } from './props';
|
|
@@ -162,19 +162,17 @@ function nativeColor(value: unknown): unknown {
|
|
|
162
162
|
return Platform.OS === 'ios' ? iosColor(value) : androidColor(value);
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
// One color, a pair for the light and the dark appearance, or a semantic color; null takes the color away.
|
|
165
|
+
// One color, a pair for the light and the dark appearance, or a semantic color; null takes the color away. A pair goes
|
|
166
|
+
// as `{ light, dark }`, an app's `DynamicColorIOS` too; a side without a color is left out and shows the platform's.
|
|
166
167
|
function iosColor(value: unknown): unknown {
|
|
167
168
|
if (value === null) return 'NoColor';
|
|
168
169
|
if (!isFields(value)) return processColor(value as ColorValue);
|
|
169
170
|
if ('semantic' in value) return value;
|
|
170
171
|
const pair = ('dynamic' in value ? value.dynamic : value) as {
|
|
171
|
-
light
|
|
172
|
-
dark
|
|
172
|
+
light?: ColorValue;
|
|
173
|
+
dark?: ColorValue;
|
|
173
174
|
};
|
|
174
|
-
return
|
|
175
|
-
light: processColor(pair.light) as ColorValue,
|
|
176
|
-
dark: processColor(pair.dark) as ColorValue,
|
|
177
|
-
});
|
|
175
|
+
return { light: processColor(pair.light), dark: processColor(pair.dark) };
|
|
178
176
|
}
|
|
179
177
|
|
|
180
178
|
// Android always takes a pair; one color goes to both, and the side without a color has none.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Options } from '../interfaces/Options';
|
|
2
|
+
|
|
3
|
+
/** What an edit of a screen's options changed: the options to merge, and the paths of the options it took out. */
|
|
4
|
+
export interface OptionsChange {
|
|
5
|
+
/** The options that are new or have another value; undefined when none. */
|
|
6
|
+
merge?: Options;
|
|
7
|
+
/** The paths of the options set before and not now, such as `['topBar', 'subtitle']`. */
|
|
8
|
+
removed: string[][];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What `next` changes of `previous`, both the options of one screen. Objects compare key by key; anything else, an
|
|
13
|
+
* array such as buttons too, changes as a whole, and a function by identity (`sameValue`).
|
|
14
|
+
*/
|
|
15
|
+
export function optionsChange(previous: Options, next: Options): OptionsChange {
|
|
16
|
+
const removed: string[][] = [];
|
|
17
|
+
const merge = changed(previous, next, [], removed) as Options | undefined;
|
|
18
|
+
return merge ? { merge, removed } : { removed };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function changed(previous: unknown, next: unknown, path: string[], removed: string[][]): unknown {
|
|
22
|
+
if (isWholeValue(path) && isPlainObject(previous) && isPlainObject(next)) {
|
|
23
|
+
if (sameValue(previous, next)) return undefined;
|
|
24
|
+
// A part of it taken out: the native side may merge the parts, so the value goes first.
|
|
25
|
+
if (Object.keys(previous).some((key) => next[key] === undefined)) removed.push(path);
|
|
26
|
+
return next;
|
|
27
|
+
}
|
|
28
|
+
if (!isPlainObject(previous) || !isPlainObject(next)) {
|
|
29
|
+
return sameValue(previous, next) ? undefined : next;
|
|
30
|
+
}
|
|
31
|
+
const result: Record<string, unknown> = {};
|
|
32
|
+
for (const [key, value] of Object.entries(next)) {
|
|
33
|
+
if (value === undefined) continue;
|
|
34
|
+
const change = changed(previous[key], value, [...path, key], removed);
|
|
35
|
+
if (change !== undefined) result[key] = change;
|
|
36
|
+
}
|
|
37
|
+
for (const [key, value] of Object.entries(previous)) {
|
|
38
|
+
if (value !== undefined && next[key] === undefined) removed.push([...path, key]);
|
|
39
|
+
}
|
|
40
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// A color (`{ light, dark }`), an icon or an image, and a menu are one value each on the native side, not a group: a
|
|
44
|
+
// part of one taken out goes as the whole value again.
|
|
45
|
+
function isWholeValue(path: string[]): boolean {
|
|
46
|
+
const key = path[path.length - 1];
|
|
47
|
+
return key !== undefined && /^(color|icon|image|menu)$|(Color|Icon|Image)$/.test(key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether two values are the same: plain objects key by key, arrays item by item, anything else, functions too, by
|
|
52
|
+
* identity. A module that ran again makes its functions anew, so they count as changed: Hermes keeps no source to tell
|
|
53
|
+
* an edited one, and sending a button's handler again costs little. With `functionsAlike` any two functions are alike.
|
|
54
|
+
*/
|
|
55
|
+
export function sameValue(a: unknown, b: unknown, functionsAlike = false): boolean {
|
|
56
|
+
if (functionsAlike && typeof a === 'function' && typeof b === 'function') return true;
|
|
57
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
58
|
+
return (
|
|
59
|
+
a.length === b.length && a.every((item, index) => sameValue(item, b[index], functionsAlike))
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
63
|
+
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
64
|
+
return [...keys].every((key) => sameValue(a[key], b[key], functionsAlike));
|
|
65
|
+
}
|
|
66
|
+
return Object.is(a, b);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
70
|
+
if (typeof value !== 'object' || value === null) return false;
|
|
71
|
+
const prototype = Object.getPrototypeOf(value);
|
|
72
|
+
return prototype === Object.prototype || prototype === null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The part of an edit's change that the screen shows the old definition's value of: where the command that showed it,
|
|
77
|
+
* or a merge since, set another value, that value stays. `before` is what the old definition gave, `own` the screen's
|
|
78
|
+
* own options now.
|
|
79
|
+
*/
|
|
80
|
+
export function changeOverOwn(change: OptionsChange, before: Options, own: Options): OptionsChange {
|
|
81
|
+
// The functions of the definition are made anew each time it is read (a chain's button handlers): any function
|
|
82
|
+
// there stands for the definition's.
|
|
83
|
+
const fromDefinition = (path: string[]) =>
|
|
84
|
+
sameValue(valueAt(own, path), valueAt(before, path), true);
|
|
85
|
+
const removed = change.removed.filter(fromDefinition);
|
|
86
|
+
const merge =
|
|
87
|
+
change.merge && (keptWhere(change.merge, [], fromDefinition) as Options | undefined);
|
|
88
|
+
return merge ? { merge, removed } : { removed };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function keptWhere(value: unknown, path: string[], keep: (path: string[]) => boolean): unknown {
|
|
92
|
+
if (!isPlainObject(value) || isWholeValue(path)) return keep(path) ? value : undefined;
|
|
93
|
+
const result: Record<string, unknown> = {};
|
|
94
|
+
for (const [key, item] of Object.entries(value)) {
|
|
95
|
+
const kept = keptWhere(item, [...path, key], keep);
|
|
96
|
+
if (kept !== undefined) result[key] = kept;
|
|
97
|
+
}
|
|
98
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The value at a path of options, such as `['topBar', 'title', 'text']`; undefined where there is none. */
|
|
102
|
+
export function valueAt(options: unknown, path: readonly string[]): unknown {
|
|
103
|
+
return path.reduce<unknown>(
|
|
104
|
+
(value, key) => (isPlainObject(value) ? value[key] : undefined),
|
|
105
|
+
options
|
|
106
|
+
);
|
|
107
|
+
}
|