feat(mobile): integrate expo-device for device type management
- Added expo-device package to manage device types. - Implemented device type initialization in the app startup process. - Created hooks and atoms for accessing device type throughout the app. - Updated navigation logic to handle iPad-specific presentation styles. - Removed unused loading indicator component. Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -22,7 +22,7 @@ class TabBarRootView: ExpoView {
|
||||
if #available(iOS 18.0, *) {
|
||||
tabBarController.isTabBarHidden = true
|
||||
}
|
||||
|
||||
|
||||
return tabBarController
|
||||
}()
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
"expo-clipboard": "7.0.1",
|
||||
"expo-constants": "17.0.8",
|
||||
"expo-dev-client": "5.0.20",
|
||||
"expo-device": "7.0.3",
|
||||
"expo-document-picker": "13.0.3",
|
||||
"expo-file-system": "18.0.12",
|
||||
"expo-haptics": "14.0.1",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { DeviceType } from "expo-device"
|
||||
import { atom } from "jotai"
|
||||
|
||||
export const loadingVisibleAtom = atom(false)
|
||||
@@ -15,3 +16,9 @@ export const loadingAtom = atom<{
|
||||
done: null,
|
||||
thenable: null,
|
||||
})
|
||||
/**
|
||||
* Do not use directly
|
||||
*/
|
||||
export const appAtoms = {
|
||||
deviceType: atom<DeviceType | null>(null),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { jotaiStore } from "@follow/utils"
|
||||
import { useAtomValue } from "jotai"
|
||||
|
||||
import { appAtoms } from "../app"
|
||||
|
||||
export const useDeviceType = () => {
|
||||
const deviceType = useAtomValue(appAtoms.deviceType)
|
||||
return deviceType
|
||||
}
|
||||
|
||||
export const getDeviceType = () => {
|
||||
return jotaiStore.get(appAtoms.deviceType)
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
import { Pressable, Text } from "react-native"
|
||||
import { useColor } from "react-native-uikit-colors"
|
||||
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import { LoginScreen } from "@/src/screens/(modal)/LoginScreen"
|
||||
import { destination } from "@/src/lib/navigation/biz/Destination"
|
||||
|
||||
import { Logo } from "../ui/logo"
|
||||
|
||||
export function NoLoginInfo({ target }: { target: "timeline" | "subscriptions" }) {
|
||||
const color = useColor("secondaryLabel")
|
||||
const navigation = useNavigation()
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
className="flex-1 items-center justify-center gap-3"
|
||||
onPress={() => navigation.presentControllerView(LoginScreen)}
|
||||
onPress={() => destination.Login()}
|
||||
>
|
||||
<Logo width={40} height={40} color={color} />
|
||||
<Text className="text-secondary-label text-xl">{`Sign in to see your ${target}`}</Text>
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
import { cn } from "@follow/utils/src/utils"
|
||||
import type { FC, PropsWithChildren } from "react"
|
||||
import { useEffect } from "react"
|
||||
import { View } from "react-native"
|
||||
import Animated, {
|
||||
Easing,
|
||||
interpolate,
|
||||
useAnimatedStyle,
|
||||
useDerivedValue,
|
||||
useSharedValue,
|
||||
withRepeat,
|
||||
withTiming,
|
||||
} from "react-native-reanimated"
|
||||
|
||||
import { Loading3CuteLiIcon } from "@/src/icons/loading_3_cute_li"
|
||||
|
||||
export const LoadingIndicator: FC<
|
||||
{
|
||||
size?: number
|
||||
color?: string
|
||||
className?: string
|
||||
} & PropsWithChildren
|
||||
> = ({ size = 36, color, children, className }) => {
|
||||
const rotateValue = useSharedValue(0)
|
||||
|
||||
const rotation = useDerivedValue(() => {
|
||||
return interpolate(rotateValue.value, [0, 360], [0, 360])
|
||||
})
|
||||
|
||||
const animatedStyle = useAnimatedStyle(() => ({
|
||||
transform: [{ rotate: `${rotation.value}deg` }],
|
||||
}))
|
||||
useEffect(() => {
|
||||
rotateValue.value = withRepeat(
|
||||
withTiming(360, { duration: 1000, easing: Easing.linear }),
|
||||
-1,
|
||||
false,
|
||||
)
|
||||
|
||||
return () => {
|
||||
rotateValue.value = 0
|
||||
}
|
||||
}, [rotateValue])
|
||||
return (
|
||||
<View className={cn("flex-1 items-center justify-center", className)}>
|
||||
<Animated.View style={[animatedStyle, { width: size, height: size }]} className={"mb-2"}>
|
||||
<Loading3CuteLiIcon width={size} height={size} color={color} />
|
||||
</Animated.View>
|
||||
{children}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { getDeviceTypeAsync } from "expo-device"
|
||||
|
||||
import { appAtoms } from "../atoms/app"
|
||||
import { jotaiStore } from "../lib/jotai"
|
||||
|
||||
export function initDeviceType() {
|
||||
getDeviceTypeAsync().then((type) => {
|
||||
jotaiStore.set(appAtoms.deviceType, type)
|
||||
})
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { initializeAppCheck } from "./app-check"
|
||||
import { initBackgroundFetch } from "./background"
|
||||
import { initCrashlytics } from "./crashlytics"
|
||||
import { initializeDayjs } from "./dayjs"
|
||||
import { initDeviceType } from "./device"
|
||||
import { hydrateDatabaseToStore, hydrateQueryClient, hydrateSettings } from "./hydrate"
|
||||
import { migrateDatabase } from "./migration"
|
||||
import { initializePlayer } from "./player"
|
||||
@@ -17,6 +18,7 @@ export const initializeApp = async () => {
|
||||
console.log(`Initialize...`)
|
||||
|
||||
const now = Date.now()
|
||||
initDeviceType()
|
||||
initializeDb()
|
||||
|
||||
await apm("migrateDatabase", migrateDatabase)
|
||||
|
||||
@@ -181,7 +181,8 @@ const ModalScreenStackItems: FC<{
|
||||
if (!rootModalRoute) {
|
||||
return null
|
||||
}
|
||||
const isStackModal = rootModalRoute.type !== "formSheet"
|
||||
const isFormSheet = rootModalRoute.type === "formSheet"
|
||||
const isStackModal = !isFormSheet
|
||||
|
||||
const isFullScreen = rootModalRoute.type !== "modal" && rootModalRoute.type !== "formSheet"
|
||||
|
||||
@@ -229,16 +230,20 @@ const ModalScreenStackItems: FC<{
|
||||
</ModalScreenItemOptionsContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
return routes.map((route) => {
|
||||
return (
|
||||
<WrappedScreenItem
|
||||
key={route.id}
|
||||
screenId={route.id}
|
||||
stackPresentation={route.type}
|
||||
screenOptions={route.screenOptions}
|
||||
>
|
||||
<ResolveView comp={route.Component} element={route.element} props={route.props} />
|
||||
</WrappedScreenItem>
|
||||
<ModalScreenItemOptionsContext.Provider value={modalScreenOptionsCtxValue} key={route.id}>
|
||||
<ModalSafeAreaInsetsContext hasTopInset={!isFormSheet}>
|
||||
<WrappedScreenItem
|
||||
screenId={route.id}
|
||||
stackPresentation={route.type}
|
||||
screenOptions={route.screenOptions}
|
||||
>
|
||||
<ResolveView comp={route.Component} element={route.element} props={route.props} />
|
||||
</WrappedScreenItem>
|
||||
</ModalSafeAreaInsetsContext>
|
||||
</ModalScreenItemOptionsContext.Provider>
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { DeviceType } from "expo-device"
|
||||
|
||||
import { getDeviceType } from "@/src/atoms/hooks/useDeviceType"
|
||||
import { LoginScreen } from "@/src/screens/(modal)/LoginScreen"
|
||||
|
||||
import { isIOS } from "../../platform"
|
||||
import { Navigation } from "../Navigation"
|
||||
|
||||
class Destination {
|
||||
private navigation = Navigation.rootNavigation
|
||||
|
||||
get isIpad() {
|
||||
return getDeviceType() === DeviceType.TABLET && isIOS
|
||||
}
|
||||
|
||||
get presentControllerView() {
|
||||
return this.navigation.presentControllerView
|
||||
}
|
||||
|
||||
get pushControllerView() {
|
||||
return this.navigation.pushControllerView
|
||||
}
|
||||
|
||||
Login() {
|
||||
this.presentControllerView(LoginScreen, void 0, this.isIpad ? "formSheet" : "modal")
|
||||
}
|
||||
}
|
||||
|
||||
export const destination = new Destination()
|
||||
@@ -1,7 +1,13 @@
|
||||
import { Platform } from "react-native"
|
||||
|
||||
import { useDeviceType } from "../atoms/hooks/useDeviceType"
|
||||
|
||||
export const isIOS = Platform.OS === "ios"
|
||||
export const isAndroid = Platform.OS === "android"
|
||||
export const isNative = isIOS || isAndroid
|
||||
export const devicePlatform = isIOS ? "ios" : isAndroid ? "android" : "web"
|
||||
export const isWeb = !isNative
|
||||
|
||||
export const useIsiPad = () => {
|
||||
return useDeviceType() && isIOS
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { deleteAsync } from "expo-file-system"
|
||||
import type { ReactNode } from "react"
|
||||
import { Button, Text, View } from "react-native"
|
||||
|
||||
import { LoadingIndicator } from "../components/ui/loading"
|
||||
import { PlatformActivityIndicator } from "../components/ui/loading/PlatformActivityIndicator"
|
||||
import { getDbPath } from "../database"
|
||||
import { BugCuteReIcon } from "../icons/bug_cute_re"
|
||||
import { useDatabaseMigration } from "../initialize/migration"
|
||||
@@ -35,9 +35,8 @@ export const MigrationProvider = ({ children }: { children: ReactNode }) => {
|
||||
if (!success) {
|
||||
return (
|
||||
<View className="flex-1 items-center justify-center">
|
||||
<LoadingIndicator>
|
||||
<Text>Database Migrations...</Text>
|
||||
</LoadingIndicator>
|
||||
<PlatformActivityIndicator />
|
||||
<Text className="text-label mt-4">Database Migrations...</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useEffect } from "react"
|
||||
import { Text, TouchableOpacity } from "react-native"
|
||||
import { Fragment, useEffect } from "react"
|
||||
import { ScrollView, Text, TouchableOpacity } from "react-native"
|
||||
|
||||
import { HeaderCloseOnly } from "@/src/components/layouts/header/HeaderElements"
|
||||
import { Navigation } from "@/src/lib/navigation/Navigation"
|
||||
import type { NavigationControllerView } from "@/src/lib/navigation/types"
|
||||
import { useIsiPad } from "@/src/lib/platform"
|
||||
import { Login } from "@/src/modules/login"
|
||||
import { useWhoami } from "@/src/store/user/hooks"
|
||||
|
||||
@@ -24,11 +25,15 @@ export const LoginScreen: NavigationControllerView = () => {
|
||||
exit()
|
||||
}
|
||||
}, [whoami])
|
||||
const isiPad = useIsiPad()
|
||||
const Container = isiPad ? ScrollView : Fragment
|
||||
|
||||
// For development purposes, we don't want to redirect to the home page automatically
|
||||
return (
|
||||
<>
|
||||
<Login />
|
||||
<Container>
|
||||
<Login />
|
||||
</Container>
|
||||
<HeaderCloseOnly />
|
||||
{!!whoami?.id && __DEV__ && (
|
||||
<TouchableOpacity
|
||||
@@ -46,3 +51,5 @@ export const LoginScreen: NavigationControllerView = () => {
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
LoginScreen.sheetGrabberVisible = false
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
"jsx": "preserve",
|
||||
"types": ["@follow/types/global"]
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts", "nativewind-env.d.ts"],
|
||||
"include": ["**/*.ts", "**/*.tsx", "nativewind-env.d.ts"],
|
||||
"exclude": ["./native", "./web-app"]
|
||||
}
|
||||
|
||||
Generated
+19
@@ -886,6 +886,9 @@ importers:
|
||||
expo-dev-client:
|
||||
specifier: 5.0.20
|
||||
version: 5.0.20(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))
|
||||
expo-device:
|
||||
specifier: 7.0.3
|
||||
version: 7.0.3(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))
|
||||
expo-document-picker:
|
||||
specifier: 13.0.3
|
||||
version: 13.0.3(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))
|
||||
@@ -8870,6 +8873,11 @@ packages:
|
||||
peerDependencies:
|
||||
expo: '*'
|
||||
|
||||
expo-device@7.0.3:
|
||||
resolution: {integrity: sha512-uNGhDYmpDj/3GySWZmRiYSt52Phdim11p0pXfgpCq/nMks0+UPZwl3D0vin5N8/gpVe5yzb13GYuFxiVoDyniw==}
|
||||
peerDependencies:
|
||||
expo: '*'
|
||||
|
||||
expo-document-picker@13.0.3:
|
||||
resolution: {integrity: sha512-348xcsiA/YhgWm1SuJNNdb5cUDpRJYCyIk8MhOU2MEDxbVRR+Q1TiUBTCIMVqaWHcxsFQzP56Wwv9n24qjeILg==}
|
||||
peerDependencies:
|
||||
@@ -14414,6 +14422,10 @@ packages:
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
|
||||
ua-parser-js@0.7.40:
|
||||
resolution: {integrity: sha512-us1E3K+3jJppDBa3Tl0L3MOJiGhe1C6P0+nIvQAFYbxlMAx0h81eOwLmU57xgqToduDDPx3y5QsdjPfDu+FgOQ==}
|
||||
hasBin: true
|
||||
|
||||
ua-parser-js@1.0.40:
|
||||
resolution: {integrity: sha512-z6PJ8Lml+v3ichVojCiB8toQJBuwR42ySM4ezjXIqXK3M0HczmKQ3LF4rhU55PfD99KEEXQG6yb7iOMyvYuHew==}
|
||||
hasBin: true
|
||||
@@ -24599,6 +24611,11 @@ snapshots:
|
||||
expo: 52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1)
|
||||
expo-dev-menu-interface: 1.9.3(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))
|
||||
|
||||
expo-device@7.0.3(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1)):
|
||||
dependencies:
|
||||
expo: 52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1)
|
||||
ua-parser-js: 0.7.40
|
||||
|
||||
expo-document-picker@13.0.3(expo@52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1)):
|
||||
dependencies:
|
||||
expo: 52.0.46(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@expo/metro-runtime@4.0.1(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)))(bufferutil@4.0.9)(encoding@0.1.13)(graphql@16.8.1)(react-native-webview@13.13.5(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1))(react-native@0.77.2(@babel/core@7.26.10)(@babel/preset-env@7.26.9(@babel/core@7.26.10))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1))(react@18.3.1)
|
||||
@@ -31237,6 +31254,8 @@ snapshots:
|
||||
|
||||
typescript@5.8.3: {}
|
||||
|
||||
ua-parser-js@0.7.40: {}
|
||||
|
||||
ua-parser-js@1.0.40: {}
|
||||
|
||||
ufo@1.6.1: {}
|
||||
|
||||
Reference in New Issue
Block a user