Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ux: Fade in inventory tab on first load #2127

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions native/app/inventory/pages/InventoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import { useEffect, useRef, useState } from "react";
import { RefreshControl, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";

import { getFullProfile } from "@/app/bungie/BungieApi.ts";
import { InventoryPageEnums, type UISections } from "@/app/inventory/logic/Helpers.ts";
import type { InventoryPageEnums, UISections } from "@/app/inventory/logic/Helpers.ts";
import { useGGStore } from "@/app/store/GGStore.ts";
import { debounce } from "@/app/utilities/Helpers.ts";
import { UiCellRenderItem } from "@/app/inventory/UiRowRenderItem.tsx";
import Animated, {
Extrapolation,
interpolate,
ReduceMotion,
useAnimatedStyle,
useSharedValue,
withSpring,
} from "react-native-reanimated";

function calcCurrentListIndex(posX: number, PAGE_WIDTH: number) {
const internalOffset = posX - PAGE_WIDTH / 2;
Expand All @@ -26,14 +34,6 @@ type Props = {
readonly pageEstimatedFlashListItemSize: number[];
};

const rootStyles = StyleSheet.create({
root: {
flex: 1,
width: "100%",
height: "100%",
},
});

const keyExtractor = (item: UISections) => item.id;
const getItemType = (item: UISections) => item.type;

Expand All @@ -48,6 +48,10 @@ export default function InventoryPage({ inventoryPageEnum, pageEstimatedFlashLis
const pageData = useGGStore((state) => state.getPageData(inventoryPageEnum));
const pullRefreshing = useGGStore((state) => state.pullRefreshing);
const [pageReady, setPageReady] = useState(false);
const opacity = useSharedValue(0);
const transferButtonStyle = useAnimatedStyle(() => ({
opacity: interpolate(opacity.value, [0, 1], [0, 1], Extrapolation.CLAMP),
}));

const jumpToCharacterRef = useRef<() => void>(() => {
const currentListIndex = useGGStore.getState().currentListIndex;
Expand Down Expand Up @@ -100,12 +104,6 @@ export default function InventoryPage({ inventoryPageEnum, pageEstimatedFlashLis
return unsubscribe;
}, []);

useEffect(() => {
if (pageReady) {
jumpToCharacterRef.current();
}
}, [pageReady]);

useFocusEffect(() => {
if (pageReady) {
jumpToCharacterRef.current();
Expand All @@ -117,9 +115,8 @@ export default function InventoryPage({ inventoryPageEnum, pageEstimatedFlashLis

const debouncedMove = debounce(listMovedRef.current, 40);
const debounceListIndex = debounce(calcCurrentListIndex, 40);
console.log("render", InventoryPageEnums[inventoryPageEnum]);
return (
<View style={[rootStyles.root, { opacity: pageReady ? 1 : 0 }]}>
<Animated.View style={[transferButtonStyle, { flex: 1, width: "100%", height: "100%" }]}>
<ScrollView
horizontal
pagingEnabled
Expand Down Expand Up @@ -149,6 +146,11 @@ export default function InventoryPage({ inventoryPageEnum, pageEstimatedFlashLis
onLoad={() => {
if (index === pageData.length - 1) {
setPageReady(true);
jumpToCharacterRef.current();
opacity.value = withSpring(1, {
duration: 1000,
reduceMotion: ReduceMotion.System,
});
}
}}
data={pageData[index]}
Expand All @@ -166,6 +168,6 @@ export default function InventoryPage({ inventoryPageEnum, pageEstimatedFlashLis
);
})}
</ScrollView>
</View>
</Animated.View>
);
}