-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ux: Fade in the header on load (#2179)
- Loading branch information
1 parent
4dead16
commit 09a0f93
Showing
5 changed files
with
131 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { TouchableOpacity, View } from "react-native"; | ||
import { Image } from "expo-image"; | ||
|
||
import { useGGStore } from "@/app/store/GGStore.ts"; | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
ReduceMotion, | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withSpring, | ||
} from "react-native-reanimated"; | ||
import { useEffect } from "react"; | ||
|
||
const scale = 0.4; | ||
const originalHeight = 96; | ||
const borderRadius = 7; | ||
const transferHeight = originalHeight * scale; | ||
|
||
export default function CharacterHeaderButtons() { | ||
"use memo"; | ||
const ggCharacters = useGGStore((state) => state.ggCharacters); | ||
const currentListIndex = useGGStore((state) => state.currentListIndex); | ||
|
||
const opacity = useSharedValue(0); | ||
const viewAnimationStyle = useAnimatedStyle(() => ({ | ||
opacity: interpolate(opacity.value, [0, 1], [0, 1], Extrapolation.CLAMP), | ||
})); | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: <This subscribes on mount> | ||
useEffect(() => { | ||
const unsubscribe = useGGStore.subscribe( | ||
(state) => state.initialPageLoaded, | ||
(initialPageLoaded, _previous) => { | ||
if (initialPageLoaded) { | ||
opacity.value = withSpring(1, { | ||
duration: 1250, | ||
reduceMotion: ReduceMotion.System, | ||
}); | ||
} | ||
}, | ||
); | ||
return unsubscribe; | ||
}, []); | ||
|
||
return ( | ||
<Animated.View style={[viewAnimationStyle, { flexDirection: "row", gap: 10 }]}> | ||
{ggCharacters.map((ggCharacter, index) => { | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => useGGStore.getState().setJumpToIndex({ index, animate: true })} | ||
key={ggCharacter.characterId} | ||
> | ||
<View | ||
style={{ | ||
width: transferHeight, | ||
height: transferHeight, | ||
borderRadius, | ||
overflow: "hidden", | ||
}} | ||
> | ||
<View | ||
style={{ | ||
transformOrigin: "top left", | ||
transform: [{ scale: scale }], | ||
}} | ||
> | ||
<Image source={ggCharacter.emblemPath} style={{ width: 96, height: 96 }} /> | ||
</View> | ||
<View | ||
style={{ | ||
position: "absolute", | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
borderRadius, | ||
borderWidth: 1, | ||
borderColor: index === currentListIndex ? "white" : "#5B5B5B", | ||
}} | ||
/> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
})} | ||
</Animated.View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
import { View } from "react-native"; | ||
import { Image } from "expo-image"; | ||
import { useEffect } from "react"; | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
ReduceMotion, | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withSpring, | ||
} from "react-native-reanimated"; | ||
|
||
import { useGGStore } from "@/app/store/GGStore.ts"; | ||
|
||
export default function InventoryHeader() { | ||
"use memo"; | ||
const totalCharacters = useGGStore((state) => state.ggCharacters.length); | ||
const currentListIndex = useGGStore((state) => state.currentListIndex); | ||
const characterBackgroundEmblem = useGGStore((state) => state.ggCharacters[currentListIndex]?.secondarySpecial); | ||
const initialPageLoaded = useGGStore((state) => state.initialPageLoaded); | ||
|
||
if (totalCharacters === 0) { | ||
return null; | ||
} | ||
const opacity = useSharedValue(0); | ||
const viewAnimationStyle = useAnimatedStyle(() => ({ | ||
opacity: interpolate(opacity.value, [0, 1], [0, 1], Extrapolation.CLAMP), | ||
})); | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: <This subscribes on mount> | ||
useEffect(() => { | ||
const unsubscribe = useGGStore.subscribe( | ||
(state) => state.initialPageLoaded, | ||
(initialPageLoaded, _previous) => { | ||
if (initialPageLoaded) { | ||
opacity.value = withSpring(1, { | ||
duration: 1250, | ||
reduceMotion: ReduceMotion.System, | ||
}); | ||
} | ||
}, | ||
); | ||
return unsubscribe; | ||
}, []); | ||
|
||
return ( | ||
<View style={{ flex: 1 }}> | ||
<Image style={{ flex: 1 }} transition={150} source={characterBackgroundEmblem} /> | ||
</View> | ||
<Animated.View style={[viewAnimationStyle, { flex: 1 }]}> | ||
<Image style={{ flex: 1 }} transition={initialPageLoaded ? 150 : 0} source={characterBackgroundEmblem} /> | ||
</Animated.View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters