refactor(mobile): refactor TabBarPortal to use native wrapper component
This commit is contained in:
parent
cee212cb2f
commit
65291ff7f0
|
|
@ -1,35 +0,0 @@
|
|||
import { requireNativeView } from "expo"
|
||||
import { useSetAtom } from "jotai"
|
||||
import { useContext } from "react"
|
||||
import type { ViewProps } from "react-native"
|
||||
import { StyleSheet, View } from "react-native"
|
||||
|
||||
import { BottomTabContext } from "./BottomTabContext"
|
||||
|
||||
const TabBarPortalNative = requireNativeView<ViewProps>("TabBarPortal")
|
||||
|
||||
export const TabBarPortal = ({ children }: { children: React.ReactNode }) => {
|
||||
const { tabHeightAtom } = useContext(BottomTabContext)
|
||||
const setTabHeight = useSetAtom(tabHeightAtom)
|
||||
return (
|
||||
// Use native view
|
||||
<TabBarPortalNative style={styles.container}>
|
||||
<View
|
||||
onLayout={(e) => {
|
||||
setTabHeight(e.nativeEvent.layout.height)
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</View>
|
||||
</TabBarPortalNative>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
position: "absolute",
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
},
|
||||
})
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
import { requireNativeView } from "expo"
|
||||
import { useSetAtom } from "jotai"
|
||||
import { useContext } from "react"
|
||||
import type { ViewProps } from "react-native"
|
||||
import { StyleSheet, View } from "react-native"
|
||||
|
||||
import { BottomTabContext } from "./BottomTabContext"
|
||||
|
||||
const TabBarPortalNative = requireNativeView<ViewProps>("TabBarPortal")
|
||||
|
||||
export const TabBarPortal = ({ children }: { children: React.ReactNode }) => {
|
||||
const { tabHeightAtom } = useContext(BottomTabContext)
|
||||
const setTabHeight = useSetAtom(tabHeightAtom)
|
||||
return (
|
||||
<TabBarPortalNative style={styles.container}>
|
||||
<View
|
||||
onLayout={(e) => {
|
||||
setTabHeight(e.nativeEvent.layout.height)
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</View>
|
||||
</TabBarPortalNative>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
position: "absolute",
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
},
|
||||
})
|
||||
|
|
@ -3,12 +3,13 @@ import { useContext } from "react"
|
|||
import { StyleSheet, View } from "react-native"
|
||||
|
||||
import { BottomTabContext } from "./BottomTabContext"
|
||||
import { TabBarPortalWrapper } from "./native"
|
||||
|
||||
export const TabBarPortal = ({ children }: { children: React.ReactNode }) => {
|
||||
const { tabHeightAtom } = useContext(BottomTabContext)
|
||||
const setTabHeight = useSetAtom(tabHeightAtom)
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TabBarPortalWrapper style={styles.container}>
|
||||
<View
|
||||
onLayout={(e) => {
|
||||
setTabHeight(e.nativeEvent.layout.height)
|
||||
|
|
@ -16,7 +17,7 @@ export const TabBarPortal = ({ children }: { children: React.ReactNode }) => {
|
|||
>
|
||||
{children}
|
||||
</View>
|
||||
</View>
|
||||
</TabBarPortalWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
import { requireNativeView } from "expo"
|
||||
import type { ViewProps } from "react-native"
|
||||
|
||||
export const TabBarPortalWrapper = requireNativeView<ViewProps>("TabBarPortal")
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
import { requireNativeView } from "expo"
|
||||
import type { ViewProps } from "react-native"
|
||||
|
||||
export const TabBarPortalWrapper = requireNativeView<ViewProps>("TabBarPortal")
|
||||
|
|
@ -0,0 +1 @@
|
|||
export { View as TabBarPortalWrapper } from "react-native"
|
||||
Loading…
Reference in New Issue