fix(mobile): merge TabScreenProps ios and other platform

- Added optional `identifier` property to `TabScreenProps` interface for better tab management.
- Updated import statements in `TabRoot` and `TabScreen` components to reference the new types file.
- Refactored `TabScreen` component to utilize the new `identifier` property in state management.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2025-04-05 21:46:05 +08:00
parent 20be007d0c
commit 2a290360d1
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
5 changed files with 17 additions and 19 deletions

View File

@ -8,8 +8,8 @@ import { StyleSheet } from "react-native"
import type { BottomTabContextType } from "./BottomTabContext"
import { BottomTabContext } from "./BottomTabContext"
import type { TabScreenProps } from "./TabScreen.ios"
import { TabScreen } from "./TabScreen.ios"
import type { TabScreenProps } from "./types"
interface TabRootProps {
initialTabIndex?: number

View File

@ -6,8 +6,8 @@ import { StyleSheet, View } from "react-native"
import type { BottomTabContextType } from "./BottomTabContext"
import { BottomTabContext } from "./BottomTabContext"
import type { TabScreenProps } from "./TabScreen"
import { TabScreen } from "./TabScreen"
import type { TabScreenProps } from "./types"
interface TabRootProps {
initialTabIndex?: number

View File

@ -10,16 +10,10 @@ import { BottomTabContext } from "./BottomTabContext"
import { LifecycleEvents, ScreenNameRegister } from "./shared"
import type { TabScreenContextType } from "./TabScreenContext"
import { TabScreenContext } from "./TabScreenContext"
import type { TabbarIconProps, TabScreenComponent } from "./types"
import type { TabScreenComponent, TabScreenProps } from "./types"
const TabScreenNative = requireNativeView<ViewProps>("TabScreen")
export interface TabScreenProps {
title: string
tabScreenIndex: number
renderIcon?: (props: TabbarIconProps) => React.ReactNode
lazy?: boolean
}
export const TabScreen: FC<PropsWithChildren<Omit<TabScreenProps, "tabScreenIndex">>> = ({
children,
...props
@ -47,6 +41,9 @@ export const TabScreen: FC<PropsWithChildren<Omit<TabScreenProps, "tabScreenInde
if ("lazy" in childType) {
propsFromChildren.lazy = childType.lazy
}
if ("identifier" in childType && typeof childType.identifier === "string") {
propsFromChildren.identifier = childType.identifier
}
}
return {
...propsFromChildren,
@ -91,10 +88,10 @@ export const TabScreen: FC<PropsWithChildren<Omit<TabScreenProps, "tabScreenInde
const ctxValue = useMemo<TabScreenContextType>(
() => ({
tabScreenIndex,
identifierAtom: atom(props.identifier ?? ""),
titleAtom: atom(props.title),
}),
[tabScreenIndex, props.title],
[tabScreenIndex, props.title, props.identifier],
)
const shouldLoadReact = mergedProps.lazy ? isSelected || isLoadedBefore : true

View File

@ -8,14 +8,8 @@ import { BottomTabContext } from "./BottomTabContext"
import { LifecycleEvents, ScreenNameRegister, TabScreenIdentifierRegister } from "./shared"
import type { TabScreenContextType } from "./TabScreenContext"
import { TabScreenContext } from "./TabScreenContext"
import type { TabbarIconProps, TabScreenComponent } from "./types"
import type { TabScreenComponent, TabScreenProps } from "./types"
export interface TabScreenProps {
title: string
tabScreenIndex: number
identifier: string
renderIcon?: (props: TabbarIconProps) => React.ReactNode
}
export const TabScreen: FC<PropsWithChildren<Omit<TabScreenProps, "tabScreenIndex">>> = ({
children,
identifier,
@ -85,7 +79,7 @@ export const TabScreen: FC<PropsWithChildren<Omit<TabScreenProps, "tabScreenInde
() => ({
tabScreenIndex,
titleAtom: atom(props.title),
identifierAtom: atom(identifier),
identifierAtom: atom(identifier ?? ""),
}),
[tabScreenIndex, props.title, identifier],
)

View File

@ -11,3 +11,10 @@ export type TabScreenComponent = FC & {
lazy?: boolean
}
export interface TabScreenProps {
title: string
tabScreenIndex: number
renderIcon?: (props: TabbarIconProps) => React.ReactNode
lazy?: boolean
identifier?: string
}