pytech-ui 1.0.35 → 1.0.36

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.
@@ -10,16 +10,13 @@ import androidx.navigation.NavHostController
10
10
  import androidx.navigation.compose.NavHost
11
11
  import androidx.navigation.compose.composable
12
12
  import androidx.navigation.compose.rememberNavController
13
+ import expo.modules.kotlin.records.Field
14
+ import expo.modules.kotlin.records.Record
13
15
  import expo.modules.kotlin.views.ComposeProps
14
16
  import expo.modules.kotlin.views.FunctionalComposableScope
15
17
  import expo.modules.pytechui.findChildBySlotName
16
18
  import expo.modules.ui.SlotView
17
19
 
18
- object PytechRoutes {
19
- const val SCREEN_A = "screen_A"
20
- const val SCREEN_B = "screen_B"
21
- }
22
-
23
20
  /**
24
21
  * Referencia global al NavController del wrapper activo.
25
22
  * Se setea al montar `NavigationWrapperView` y se limpia al desmontarlo.
@@ -39,13 +36,22 @@ object PytechNavigation {
39
36
  /** Disponible para cualquier composable renderizado dentro del wrapper. */
40
37
  val LocalPytechNavController = staticCompositionLocalOf<NavHostController?> { null }
41
38
 
39
+ data class NavigationRouteRecord(
40
+ @Field val route: String = "",
41
+ ) : Record
42
+
42
43
  data class NavigationWrapperProps(
43
- val startDestination: String = PytechRoutes.SCREEN_A,
44
+ val routes: List<NavigationRouteRecord> = emptyList(),
45
+ val startDestination: String = "",
44
46
  ) : ComposeProps
45
47
 
46
48
  @Composable
47
49
  internal fun FunctionalComposableScope.NavigationWrapperViewContent(props: NavigationWrapperProps) {
48
50
  val navController = rememberNavController()
51
+ val routeNames = props.routes.map { it.route }.filter { it.isNotEmpty() }
52
+ val startDestination = props.startDestination.takeIf { it.isNotEmpty() }
53
+ ?: routeNames.firstOrNull()
54
+ ?: return
49
55
 
50
56
  DisposableEffect(navController) {
51
57
  PytechNavigation.navController = navController
@@ -56,17 +62,16 @@ internal fun FunctionalComposableScope.NavigationWrapperViewContent(props: Navig
56
62
  }
57
63
  }
58
64
 
59
- val screenA = findChildBySlotName(PytechRoutes.SCREEN_A)
60
- val screenB = findChildBySlotName(PytechRoutes.SCREEN_B)
61
-
62
65
  CompositionLocalProvider(LocalPytechNavController provides navController) {
63
66
  NavHost(
64
67
  navController = navController,
65
- startDestination = props.startDestination,
68
+ startDestination = startDestination,
66
69
  modifier = Modifier.fillMaxSize(),
67
70
  ) {
68
- composable(PytechRoutes.SCREEN_A) { RenderScreen(screenA) }
69
- composable(PytechRoutes.SCREEN_B) { RenderScreen(screenB) }
71
+ routeNames.forEach { route ->
72
+ val slot = findChildBySlotName(route)
73
+ composable(route) { RenderScreen(slot) }
74
+ }
70
75
  }
71
76
  }
72
77
  }
@@ -1,4 +1,3 @@
1
1
  import { HostProps as ExpoHostProps } from '@expo/ui/jetpack-compose';
2
- import { NavigationWrapperProps } from './NavigationWrapper';
3
- export type HostProps = ExpoHostProps & Partial<Omit<NavigationWrapperProps, 'screenA' | 'startDestination'>>;
4
- export declare const Host: ({ style, screenB, ...props }: HostProps) => import("react").JSX.Element;
2
+ export type HostProps = ExpoHostProps;
3
+ export declare const Host: ({ style, children, ...props }: HostProps) => import("react").JSX.Element;
@@ -3,14 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Host = void 0;
4
4
  const expo_1 = require("expo");
5
5
  const jetpack_compose_1 = require("@expo/ui/jetpack-compose");
6
- const NavigationWrapper_1 = require("./NavigationWrapper");
7
6
  const ExtendedTheme = (0, expo_1.requireNativeView)('PytechUi', 'ExtendedTheme');
8
- const Host = ({ style, screenB, ...props }) => {
9
- const hasNavigation = screenB != null;
10
- return (<jetpack_compose_1.Host style={{ flex: 1, ...style }} {...props}>
11
- <ExtendedTheme>
12
- {hasNavigation ? (<NavigationWrapper_1.NavigationWrapper screenA={props.children} screenB={screenB} startDestination='screen_A'/>) : (props.children)}
13
- </ExtendedTheme>
14
- </jetpack_compose_1.Host>);
15
- };
7
+ const Host = ({ style, children, ...props }) => (<jetpack_compose_1.Host style={{ flex: 1, ...style }} {...props}>
8
+ <ExtendedTheme>{children}</ExtendedTheme>
9
+ </jetpack_compose_1.Host>);
16
10
  exports.Host = Host;
@@ -1,10 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
- export type NavigationRoute = 'screen_A' | 'screen_B';
2
+ export type NavigationRouteDefinition = {
3
+ route: string;
4
+ screen: ReactNode;
5
+ };
3
6
  export type NavigationWrapperProps = {
4
- screenA: ReactNode;
5
- screenB: ReactNode;
6
- startDestination?: NavigationRoute;
7
+ routes: NavigationRouteDefinition[];
8
+ startDestination?: string;
7
9
  };
8
- export declare const navigate: (route: NavigationRoute) => Promise<void>;
10
+ export declare const navigate: (route: string) => Promise<void>;
9
11
  export declare const goBack: () => Promise<boolean>;
10
- export declare const NavigationWrapper: ({ screenA, screenB, startDestination }: NavigationWrapperProps) => import("react").JSX.Element;
12
+ export declare const NavigationWrapper: ({ routes, startDestination }: NavigationWrapperProps) => import("react").JSX.Element;
@@ -9,8 +9,12 @@ const navigate = (route) => Native.navigate(route);
9
9
  exports.navigate = navigate;
10
10
  const goBack = () => Native.goBack();
11
11
  exports.goBack = goBack;
12
- const NavigationWrapper = ({ screenA, screenB, startDestination }) => (<NavigationWrapperNativeView startDestination={startDestination}>
13
- <SlotNativeView slotName="screen_A">{screenA}</SlotNativeView>
14
- <SlotNativeView slotName="screen_B">{screenB}</SlotNativeView>
15
- </NavigationWrapperNativeView>);
12
+ const NavigationWrapper = ({ routes, startDestination }) => {
13
+ const resolvedStartDestination = startDestination ?? routes[0]?.route;
14
+ return (<NavigationWrapperNativeView routes={routes.map(({ route }) => ({ route }))} startDestination={resolvedStartDestination}>
15
+ {routes.map(({ route, screen }) => (<SlotNativeView key={route} slotName={route}>
16
+ {screen}
17
+ </SlotNativeView>))}
18
+ </NavigationWrapperNativeView>);
19
+ };
16
20
  exports.NavigationWrapper = NavigationWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pytech-ui",
3
- "version": "1.0.35",
3
+ "version": "1.0.36",
4
4
  "description": "Librería de componentes de UI para Pytech",
5
5
  "keywords": [
6
6
  "react-native",