react-nitro-navigation 0.0.0-stage → 0.0.1-alpha.7
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/Package.swift +104 -0
- package/README.md +20 -2
- package/Sources/ReactNitroNavigation/HybridNavigationScreen.swift +27 -0
- package/Sources/ReactNitroNavigation/HybridNavigationStack.swift +103 -0
- package/Sources/ReactNitroNavigation/NavigationControllerDelegate.swift +11 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/apple/ReactNitroNavigation-Swift-Cxx-Bridge.cpp +109 -0
- package/nitrogen/generated/apple/ReactNitroNavigationAppleCxx/ReactNitroNavigationAppleCxx.cpp +9 -0
- package/nitrogen/generated/apple/ReactNitroNavigationAppleCxx/include/ReactNitroNavigationAppleCxx/ReactNitroNavigationAppleCxx.h +120 -0
- package/nitrogen/generated/apple/ReactNitroNavigationAutolinking.cpp +22 -0
- package/nitrogen/generated/apple/ReactNitroNavigationAutolinking.mm +24 -0
- package/nitrogen/generated/apple/c++/HybridNavigationScreenSpecSwift.cpp +54 -0
- package/nitrogen/generated/apple/c++/HybridNavigationScreenSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/HybridNavigationStackSpecSwift.cpp +69 -0
- package/nitrogen/generated/apple/c++/HybridNavigationStackSpec_cxx-Swift.cpp +28 -0
- package/nitrogen/generated/apple/c++/ListenerSubscription-Swift.cpp +37 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/ReactNitroNavigationAutolinking.hpp +13 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/HybridNavigationScreenSpecSwift.hpp +75 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/HybridNavigationScreenSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/HybridNavigationStackSpecSwift.hpp +75 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/HybridNavigationStackSpec_cxx-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/ListenerSubscription-Swift.hpp +23 -0
- package/nitrogen/generated/apple/c++/include/ReactNitroNavigation/private/ReactNitroNavigation-Swift-Cxx-Umbrella.hpp +48 -0
- package/nitrogen/generated/apple/c++/include/module.modulemap +12 -0
- package/nitrogen/generated/apple/swift/Callback_void.swift +60 -0
- package/nitrogen/generated/apple/swift/Callback_void_double.swift +60 -0
- package/nitrogen/generated/apple/swift/HybridNavigationScreenSpec.swift +68 -0
- package/nitrogen/generated/apple/swift/HybridNavigationScreenSpec_cxx.swift +163 -0
- package/nitrogen/generated/apple/swift/HybridNavigationStackSpec.swift +69 -0
- package/nitrogen/generated/apple/swift/HybridNavigationStackSpec_cxx.swift +177 -0
- package/nitrogen/generated/apple/swift/ListenerSubscription.swift +29 -0
- package/nitrogen/generated/apple/swift/Promise_void.swift +100 -0
- package/nitrogen/generated/hybrid-classes.json +21 -0
- package/nitrogen/generated/shared/c++/ReactNitroNavigationCxxModule.cpp +2 -0
- package/nitrogen/generated/shared/c++/include/ReactNitroNavigation/ReactNitroNavigationCxxModule.hpp +2 -0
- package/nitrogen/generated/shared/javascript/NavigationScreen.cjs +19 -0
- package/nitrogen/generated/shared/javascript/NavigationScreen.d.cts +9 -0
- package/nitrogen/generated/shared/javascript/NavigationStack.cjs +19 -0
- package/nitrogen/generated/shared/javascript/NavigationStack.d.cts +9 -0
- package/package.json +33 -4
- package/src/NativeScreenHost.ts +18 -0
- package/src/NativeStackHost.ts +14 -0
- package/src/StackNavigationOptions.ts +7 -0
- package/src/StackNavigationProp.ts +8 -0
- package/src/StackScreen.tsx +19 -0
- package/src/createStackNavigator.tsx +67 -0
- package/src/index.ts +4 -0
- package/src/specs/NavigationScreen.nitro.ts +17 -0
- package/src/specs/NavigationStack.nitro.ts +20 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { registerView, viewPropsSetters, type ViewProps } from 'react-nitro-renderer'
|
|
2
|
+
import type { NavigationStack } from './specs/NavigationStack.nitro'
|
|
3
|
+
|
|
4
|
+
interface NativeStackHostProps extends ViewProps {
|
|
5
|
+
stack: NavigationStack
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module 'react-nitro-renderer' {
|
|
9
|
+
interface ViewDefinitionMap {
|
|
10
|
+
NavigationStack: { view: NavigationStack; props: NativeStackHostProps }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const NativeStackHost = registerView('NavigationStack', (props) => props.stack, viewPropsSetters)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { createStackNavigator } from './createStackNavigator'
|
|
2
|
+
|
|
3
|
+
/** Screen options accepted by {@link createStackNavigator}. */
|
|
4
|
+
export interface StackNavigationOptions {
|
|
5
|
+
/** The native navigation bar title. Defaults to the route name. */
|
|
6
|
+
title?: string
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NavigationProp, ParamListBase } from '@react-navigation/core'
|
|
2
|
+
import type { StackActionHelpers, StackNavigationState } from '@react-navigation/routers'
|
|
3
|
+
import type { StackNavigationOptions } from './StackNavigationOptions'
|
|
4
|
+
|
|
5
|
+
/** Navigation commands exposed to screens in a Nitro stack. */
|
|
6
|
+
export type StackNavigationProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = keyof ParamList> = NavigationProp<
|
|
7
|
+
ParamList, RouteName, undefined, StackNavigationState<ParamList>, StackNavigationOptions, {}
|
|
8
|
+
> & StackActionHelpers<ParamList>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react'
|
|
2
|
+
import { ViewControllerContext } from 'react-nitro-renderer'
|
|
3
|
+
import { NativeScreenHost } from './NativeScreenHost'
|
|
4
|
+
import { NavigationScreen } from './specs/NavigationScreen.nitro'
|
|
5
|
+
|
|
6
|
+
export function StackScreen({ children, title }: { children: ReactNode; title: string }) {
|
|
7
|
+
const [screen] = useState(() => new NavigationScreen())
|
|
8
|
+
return (
|
|
9
|
+
<ViewControllerContext.Provider value={screen.viewController}>
|
|
10
|
+
<NativeScreenHost
|
|
11
|
+
screen={screen}
|
|
12
|
+
title={title}
|
|
13
|
+
layout={{ position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 }}
|
|
14
|
+
>
|
|
15
|
+
{children}
|
|
16
|
+
</NativeScreenHost>
|
|
17
|
+
</ViewControllerContext.Provider>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNavigatorFactory,
|
|
3
|
+
useNavigationBuilder,
|
|
4
|
+
type DefaultNavigatorOptions,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
type TypedNavigator,
|
|
7
|
+
} from '@react-navigation/core'
|
|
8
|
+
import { StackActions, StackRouter, type StackActionHelpers, type StackNavigationState, type StackRouterOptions } from '@react-navigation/routers'
|
|
9
|
+
import { useLayoutEffect, useState } from 'react'
|
|
10
|
+
import { useRootContext } from 'react-nitro-renderer'
|
|
11
|
+
import { NativeStackHost } from './NativeStackHost'
|
|
12
|
+
import { StackScreen } from './StackScreen'
|
|
13
|
+
import { NavigationStack } from './specs/NavigationStack.nitro'
|
|
14
|
+
import type { StackNavigationOptions } from './StackNavigationOptions'
|
|
15
|
+
import type { StackNavigationProp } from './StackNavigationProp'
|
|
16
|
+
|
|
17
|
+
type NavigatorProps = DefaultNavigatorOptions<
|
|
18
|
+
ParamListBase, undefined, StackNavigationState<ParamListBase>,
|
|
19
|
+
StackNavigationOptions, {}, StackNavigationProp<ParamListBase>
|
|
20
|
+
> & StackRouterOptions
|
|
21
|
+
|
|
22
|
+
function StackNavigator(props: NavigatorProps) {
|
|
23
|
+
const { state, navigation, descriptors, render } = useNavigationBuilder<
|
|
24
|
+
StackNavigationState<ParamListBase>, StackRouterOptions,
|
|
25
|
+
StackActionHelpers<ParamListBase>, StackNavigationOptions, {}
|
|
26
|
+
>(StackRouter, props)
|
|
27
|
+
const parent = useRootContext()
|
|
28
|
+
const [stack] = useState(() => new NavigationStack())
|
|
29
|
+
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
stack.attachTo(parent)
|
|
32
|
+
const subscription = stack.addOnPopListener((count) => {
|
|
33
|
+
const action = StackActions.pop(count)
|
|
34
|
+
navigation.dispatch({ ...action, target: state.key })
|
|
35
|
+
})
|
|
36
|
+
return () => {
|
|
37
|
+
subscription.remove()
|
|
38
|
+
stack.removeFromParent()
|
|
39
|
+
}
|
|
40
|
+
}, [stack, parent, navigation, state.key])
|
|
41
|
+
|
|
42
|
+
const screens = state.routes.map((route) => {
|
|
43
|
+
const descriptor = descriptors[route.key]
|
|
44
|
+
if (descriptor === undefined) {
|
|
45
|
+
throw new Error(`Missing descriptor for ${route.name}`)
|
|
46
|
+
}
|
|
47
|
+
const title = descriptor.options.title ?? route.name
|
|
48
|
+
const element = descriptor.render()
|
|
49
|
+
return <StackScreen key={route.key} title={title}>{element}</StackScreen>
|
|
50
|
+
})
|
|
51
|
+
const content = <NativeStackHost stack={stack} layout={{ flex: 1 }}>{screens}</NativeStackHost>
|
|
52
|
+
return render(content)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type StackTypeBag<ParamList extends ParamListBase> = {
|
|
56
|
+
ParamList: ParamList
|
|
57
|
+
NavigatorID: undefined
|
|
58
|
+
State: StackNavigationState<ParamList>
|
|
59
|
+
ScreenOptions: StackNavigationOptions
|
|
60
|
+
EventMap: {}
|
|
61
|
+
NavigationList: { [RouteName in keyof ParamList]: StackNavigationProp<ParamList, RouteName> }
|
|
62
|
+
Navigator: typeof StackNavigator
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Creates a minimal UIKit stack navigator backed by React Navigation's router. */
|
|
66
|
+
export const createStackNavigator: <ParamList extends ParamListBase>() => TypedNavigator<StackTypeBag<ParamList>> =
|
|
67
|
+
createNavigatorFactory(StackNavigator)
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BaseNavigationContainer as NavigationContainer, useNavigation, useRoute } from '@react-navigation/core'
|
|
2
|
+
export { createStackNavigator } from './createStackNavigator'
|
|
3
|
+
export type { StackNavigationOptions } from './StackNavigationOptions'
|
|
4
|
+
export type { StackNavigationProp } from './StackNavigationProp'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { iOS } from 'nitro-core'
|
|
2
|
+
import type { View, ViewController } from 'react-nitro-renderer/hybrids'
|
|
3
|
+
|
|
4
|
+
export * from '#nitro/NavigationScreen'
|
|
5
|
+
|
|
6
|
+
/** A React host view whose native placement is managed by the stack controller. */
|
|
7
|
+
@iOS({
|
|
8
|
+
language: 'swift',
|
|
9
|
+
implementation: { className: 'HybridNavigationScreen' },
|
|
10
|
+
})
|
|
11
|
+
export declare class NavigationScreen extends View {
|
|
12
|
+
public constructor()
|
|
13
|
+
/** The controller hosting this screen's children. */
|
|
14
|
+
readonly viewController: ViewController
|
|
15
|
+
/** The native navigation bar title. */
|
|
16
|
+
title: string | undefined
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { iOS } from 'nitro-core'
|
|
2
|
+
import type { View, ViewController } from 'react-nitro-renderer/hybrids'
|
|
3
|
+
import type { ListenerSubscription } from 'react-nitro-renderer'
|
|
4
|
+
|
|
5
|
+
export * from '#nitro/NavigationStack'
|
|
6
|
+
|
|
7
|
+
/** Native host for the screens rendered by the stack navigator. */
|
|
8
|
+
@iOS({
|
|
9
|
+
language: 'swift',
|
|
10
|
+
implementation: { className: 'HybridNavigationStack' },
|
|
11
|
+
})
|
|
12
|
+
export declare class NavigationStack extends View {
|
|
13
|
+
public constructor()
|
|
14
|
+
/** Embeds the stack controller in its enclosing screen controller. */
|
|
15
|
+
attachTo(parent: ViewController): void
|
|
16
|
+
/** Removes the stack controller from its parent. */
|
|
17
|
+
removeFromParent(): void
|
|
18
|
+
/** Observes the number of screens removed by a completed native back action. */
|
|
19
|
+
addOnPopListener(listener: (count: number) => void): ListenerSubscription
|
|
20
|
+
}
|