refactor(mobile): improve view selector and tab layout components
- Replace PlatformPressable with Pressable in tab layout - Add separator between views and lists in view selector - Use ReAnimatedTouchableOpacity and useAnimatedStyle - Simplify color and styling imports Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -4,11 +4,11 @@ import type { ListRenderItemInfo } from "@shopify/flash-list"
|
||||
import { FlashList } from "@shopify/flash-list"
|
||||
import { Image } from "expo-image"
|
||||
import { router } from "expo-router"
|
||||
import { useColorScheme } from "nativewind"
|
||||
import { useCallback, useContext, useMemo } from "react"
|
||||
import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native"
|
||||
import { RefreshControl, StyleSheet, Text, useAnimatedValue, View } from "react-native"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { useColor } from "react-native-uikit-colors"
|
||||
|
||||
import {
|
||||
NavigationBlurEffectHeader,
|
||||
@@ -79,7 +79,6 @@ function EntryListContent({ entryIds }: { entryIds: string[] }) {
|
||||
: originalDefaultHeaderHeight
|
||||
const scrollY = useContext(NavigationContext)?.scrollY
|
||||
|
||||
const { colorScheme } = useColorScheme()
|
||||
const { fetchNextPage, isFetching, refetch, isRefetching } = useFetchEntriesControls()
|
||||
|
||||
const onScroll = useCallback(
|
||||
@@ -102,13 +101,15 @@ function EntryListContent({ entryIds }: { entryIds: string[] }) {
|
||||
[isFetching, screenType],
|
||||
)
|
||||
|
||||
const systemFill = useColor("secondaryLabel")
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
progressViewOffset={headerHeight}
|
||||
// FIXME: not sure why we need set tintColor manually here, otherwise we can not see the refresh indicator
|
||||
tintColor={colorScheme === "dark" ? "white" : "black"}
|
||||
// // FIXME: not sure why we need set tintColor manually here, otherwise we can not see the refresh indicator
|
||||
tintColor={systemFill}
|
||||
onRefresh={() => {
|
||||
refetch()
|
||||
}}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import { Image } from "expo-image"
|
||||
import { useEffect } from "react"
|
||||
import type { StyleProp, ViewStyle } from "react-native"
|
||||
import { ScrollView, Text, TouchableOpacity, View } from "react-native"
|
||||
import { ScrollView, StyleSheet, Text, View } from "react-native"
|
||||
import { Grayscale } from "react-native-color-matrix-image-filters"
|
||||
import Animated, { useSharedValue, withSpring } from "react-native-reanimated"
|
||||
import { useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated"
|
||||
|
||||
import { ReAnimatedTouchableOpacity } from "@/src/components/common/AnimatedComponents"
|
||||
import { FallbackIcon } from "@/src/components/ui/icon/fallback-icon"
|
||||
import type { ViewDefinition } from "@/src/constants/views"
|
||||
import { views } from "@/src/constants/views"
|
||||
import { useList } from "@/src/store/list/hooks"
|
||||
import { useAllListSubscription } from "@/src/store/subscription/hooks"
|
||||
import { useColor } from "@/src/theme/colors"
|
||||
import { accentColor, useColor } from "@/src/theme/colors"
|
||||
|
||||
import { selectTimeline, useSelectedFeed } from "../feed-drawer/atoms"
|
||||
|
||||
@@ -27,6 +28,7 @@ export function ViewSelector() {
|
||||
{views.map((view) => (
|
||||
<ViewItem key={view.name} view={view} />
|
||||
))}
|
||||
{lists.length > 0 && <View className="bg-opaque-separator mx-3 h-8 w-px" />}
|
||||
{lists.map((listId) => (
|
||||
<ListItem key={listId} listId={listId} />
|
||||
))}
|
||||
@@ -35,8 +37,6 @@ export function ViewSelector() {
|
||||
)
|
||||
}
|
||||
|
||||
const AnimatedTouchableOpacity = Animated.createAnimatedComponent(TouchableOpacity)
|
||||
|
||||
function ItemWrapper({
|
||||
children,
|
||||
isActive,
|
||||
@@ -56,17 +56,17 @@ function ItemWrapper({
|
||||
}, [isActive, width])
|
||||
|
||||
return (
|
||||
<AnimatedTouchableOpacity
|
||||
<ReAnimatedTouchableOpacity
|
||||
className="relative flex h-12 flex-row items-center justify-center gap-2 overflow-hidden rounded-[1.2rem]"
|
||||
onPress={onPress}
|
||||
style={{
|
||||
style={useAnimatedStyle(() => ({
|
||||
backgroundColor: bgColor,
|
||||
width,
|
||||
width: width.value,
|
||||
...style,
|
||||
}}
|
||||
}))}
|
||||
>
|
||||
{children}
|
||||
</AnimatedTouchableOpacity>
|
||||
</ReAnimatedTouchableOpacity>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ function ViewItem({ view }: { view: ViewDefinition }) {
|
||||
function ListItem({ listId }: { listId: string }) {
|
||||
const list = useList(listId)
|
||||
const selectedFeed = useSelectedFeed()
|
||||
const bgColor = useColor("orange")
|
||||
|
||||
if (!selectedFeed) return null
|
||||
const isActive = selectedFeed.type === "list" && selectedFeed.listId === listId
|
||||
|
||||
@@ -105,7 +105,7 @@ function ListItem({ listId }: { listId: string }) {
|
||||
<ItemWrapper
|
||||
isActive={isActive}
|
||||
onPress={() => selectTimeline({ type: "list", listId })}
|
||||
style={isActive ? { backgroundColor: bgColor } : undefined}
|
||||
style={isActive ? { backgroundColor: accentColor } : undefined}
|
||||
>
|
||||
{list.image ? (
|
||||
isActive ? (
|
||||
@@ -116,14 +116,7 @@ function ListItem({ listId }: { listId: string }) {
|
||||
</Grayscale>
|
||||
)
|
||||
) : (
|
||||
<FallbackIcon
|
||||
title={list.title}
|
||||
size={28}
|
||||
gray={!isActive}
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
}}
|
||||
/>
|
||||
<FallbackIcon title={list.title} size={28} gray={!isActive} style={styles.fallbackIcon} />
|
||||
)}
|
||||
{isActive && (
|
||||
<Text className="max-w-24 text-sm font-semibold text-white" numberOfLines={1}>
|
||||
@@ -133,3 +126,9 @@ function ListItem({ listId }: { listId: string }) {
|
||||
</ItemWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
fallbackIcon: {
|
||||
borderRadius: 8,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { PlatformPressable } from "@react-navigation/elements/src/PlatformPressable"
|
||||
import { router, Tabs } from "expo-router"
|
||||
import { useContext, useEffect, useMemo, useState } from "react"
|
||||
import { Animated as RNAnimated, Easing, StyleSheet, useAnimatedValue, View } from "react-native"
|
||||
import {
|
||||
Animated as RNAnimated,
|
||||
Easing,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
useAnimatedValue,
|
||||
View,
|
||||
} from "react-native"
|
||||
import { Gesture, GestureDetector } from "react-native-gesture-handler"
|
||||
import Animated, { runOnJS, useAnimatedStyle, useSharedValue } from "react-native-reanimated"
|
||||
|
||||
@@ -93,7 +99,7 @@ export default function TabLayout() {
|
||||
return (
|
||||
<GestureDetector gesture={doubleTap}>
|
||||
<View className="flex-1">
|
||||
<PlatformPressable {...props} />
|
||||
<Pressable {...props} />
|
||||
</View>
|
||||
</GestureDetector>
|
||||
)
|
||||
@@ -109,6 +115,9 @@ export default function TabLayout() {
|
||||
const Icon = !focused ? SafariCuteIcon : SafariCuteFi
|
||||
return <Icon color={color} width={24} height={24} />
|
||||
},
|
||||
tabBarButton(props) {
|
||||
return <Pressable {...props} />
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -121,7 +130,7 @@ export default function TabLayout() {
|
||||
return (
|
||||
<GestureDetector gesture={fifthTap}>
|
||||
<View className="flex-1">
|
||||
<PlatformPressable {...props} />
|
||||
<Pressable {...props} />
|
||||
</View>
|
||||
</GestureDetector>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user