generated from coral-xyz/xnft-quickstart
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Get rid of react-native-skeleton-content
– required to upgrade Expo to 49 and to fix issues with react-reanimated being outdated – reduces bundle size
- Loading branch information
Showing
7 changed files
with
103 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,68 @@ | ||
import tw from "@src/utils/tailwind"; | ||
import React, { useRef, useEffect, useState, ReactNode } from "react"; | ||
import { Animated, type LayoutChangeEvent, View, Easing } from "react-native"; | ||
import { LinearGradient } from "expo-linear-gradient"; | ||
|
||
const AnimatedGradient = Animated.createAnimatedComponent(LinearGradient); | ||
|
||
interface SkeletonProps { | ||
style?: ReturnType<typeof tw>; | ||
bgColor?: string; | ||
isLoading?: boolean; | ||
children?: ReactNode; | ||
} | ||
|
||
export const Skeleton = ({ | ||
style, | ||
bgColor = "#e1e9ee", | ||
isLoading = false, | ||
children, | ||
}: SkeletonProps = {}) => { | ||
const translateX = useRef(new Animated.Value(-1)).current; | ||
const [width, setWidth] = useState(0); | ||
|
||
useEffect(() => { | ||
Animated.loop( | ||
Animated.sequence([ | ||
Animated.timing(translateX, { | ||
toValue: 1, | ||
duration: 1200, | ||
useNativeDriver: false, | ||
easing: Easing.ease, | ||
}), | ||
]) | ||
).start(); | ||
}, [translateX]); | ||
|
||
const translateXStyle = { | ||
transform: [ | ||
{ | ||
translateX: translateX.interpolate({ | ||
inputRange: [-1, 1], | ||
outputRange: [-width * 2, width * 2], | ||
}), | ||
}, | ||
], | ||
}; | ||
|
||
const onLayout = (event: LayoutChangeEvent) => { | ||
const { width: newWidth } = event.nativeEvent.layout; | ||
setWidth(newWidth); | ||
}; | ||
|
||
return isLoading ? ( | ||
<View | ||
style={[style, tw`overflow-hidden bg-[${bgColor}]`]} | ||
onLayout={onLayout} | ||
> | ||
<AnimatedGradient | ||
colors={[bgColor, "#F2F8FC", bgColor]} | ||
start={{ x: 0, y: 0 }} | ||
end={{ x: 1, y: 0 }} | ||
style={[translateXStyle, tw`w-full h-full`]} | ||
/> | ||
</View> | ||
) : ( | ||
<>{children}</> | ||
); | ||
}; |
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
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