Skip to content

Instantly share code, notes, and snippets.

@thierryskoda
Created October 16, 2024 00:02
Show Gist options
  • Save thierryskoda/f8343c45f4e3edcf1d9f944775029e47 to your computer and use it in GitHub Desktop.
Save thierryskoda/f8343c45f4e3edcf1d9f944775029e47 to your computer and use it in GitHub Desktop.
Ignite welcome screen component
import { observer } from "mobx-react-lite"
import { FC } from "react"
import { Image, ImageStyle, TextStyle, View, ViewStyle } from "react-native"
import { Button, Text, Screen } from "@/components"
import { isRTL } from "../i18n"
import { useStores } from "../models"
import { AppStackScreenProps } from "../navigators"
import type { ThemedStyle } from "@/theme"
import { useHeader } from "../utils/useHeader"
import { useSafeAreaInsetsStyle } from "../utils/useSafeAreaInsetsStyle"
import { useAppTheme } from "@/utils/useAppTheme"
const welcomeLogo = require("../../assets/images/logo.png")
const welcomeFace = require("../../assets/images/welcome-face.png")
interface WelcomeScreenProps extends AppStackScreenProps<"Welcome"> {}
export const WelcomeScreen: FC<WelcomeScreenProps> = observer(function WelcomeScreen(_props) {
const { themed, theme } = useAppTheme()
const { navigation } = _props
const {
authenticationStore: { logout },
} = useStores()
function goNext() {
navigation.navigate("Demo", { screen: "DemoShowroom", params: {} })
}
useHeader(
{
rightTx: "common:logOut",
onRightPress: logout,
},
[logout],
)
const $bottomContainerInsets = useSafeAreaInsetsStyle(["bottom"])
return (
<Screen preset="fixed">
<View style={themed($topContainer)}>
<Image style={themed($welcomeLogo)} source={welcomeLogo} resizeMode="contain" />
<Text
testID="welcome-heading"
style={themed($welcomeHeading)}
tx="welcomeScreen:readyForLaunch"
preset="heading"
/>
<Text tx="welcomeScreen:exciting" preset="subheading" />
<Image
style={$welcomeFace}
source={welcomeFace}
resizeMode="contain"
tintColor={theme.isDark ? theme.colors.palette.neutral900 : undefined}
/>
</View>
<View style={themed([$bottomContainer, $bottomContainerInsets])}>
<Text tx="welcomeScreen:postscript" size="md" />
<Button
testID="next-screen-button"
preset="reversed"
tx="welcomeScreen:letsGo"
onPress={goNext}
/>
</View>
</Screen>
)
})
const $topContainer: ThemedStyle<ViewStyle> = ({ spacing }) => ({
flexShrink: 1,
flexGrow: 1,
flexBasis: "57%",
justifyContent: "center",
paddingHorizontal: spacing.lg,
})
const $bottomContainer: ThemedStyle<ViewStyle> = ({ colors, spacing }) => ({
flexShrink: 1,
flexGrow: 0,
flexBasis: "43%",
backgroundColor: colors.palette.neutral100,
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
paddingHorizontal: spacing.lg,
justifyContent: "space-around",
})
const $welcomeLogo: ThemedStyle<ImageStyle> = ({ spacing }) => ({
height: 88,
width: "100%",
marginBottom: spacing.xxl,
})
const $welcomeFace: ImageStyle = {
height: 169,
width: 269,
position: "absolute",
bottom: -47,
right: -80,
transform: [{ scaleX: isRTL ? -1 : 1 }],
}
const $welcomeHeading: ThemedStyle<TextStyle> = ({ spacing }) => ({
marginBottom: spacing.md,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment