-
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.
Merge pull request #16 from Circle-Company/add-skeleton-view
Add Skeleton Loading on Account Screen + AllMemoriesScreen
- Loading branch information
Showing
13 changed files
with
415 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,5 @@ | ||
import { SkeletonView } from "./skeleton-view" | ||
|
||
export const Skeleton = { | ||
View: SkeletonView, | ||
} |
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,76 @@ | ||
import React from "react" | ||
import { StyleSheet, ViewProps, useColorScheme } from "react-native" | ||
import LinearGradient from "react-native-linear-gradient" | ||
import Animated, { | ||
interpolate, | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withRepeat, | ||
withTiming, | ||
} from "react-native-reanimated" | ||
import { View } from "../../components/Themed" | ||
import { colors } from "../../layout/constants/colors" | ||
import sizes from "../../layout/constants/sizes" | ||
|
||
const width = sizes.screens.width | ||
const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient) | ||
|
||
interface SkeletonViewProps extends ViewProps { | ||
children?: React.ReactNode | ||
delay?: number | ||
backgroundColor?: string | ||
gradientColor?: string | ||
} | ||
|
||
export const SkeletonView = React.memo( | ||
({ | ||
children, | ||
style, | ||
delay = 0, | ||
backgroundColor, | ||
gradientColor, | ||
...props | ||
}: SkeletonViewProps) => { | ||
const isDarkMode = useColorScheme() === "dark" | ||
const x = useSharedValue(0) | ||
|
||
React.useEffect(() => { | ||
const startAnimation = () => { | ||
x.value = withRepeat(withTiming(1, { duration: 1500 }), -1, false) | ||
} | ||
const timeoutId = setTimeout(startAnimation, delay) | ||
return () => clearTimeout(timeoutId) | ||
}, [delay]) | ||
|
||
const containerStyle = React.useMemo( | ||
() => ({ | ||
backgroundColor: | ||
backgroundColor || isDarkMode ? colors.gray.grey_08 : colors.gray.grey_02, | ||
overflow: "hidden", | ||
}), | ||
[backgroundColor] | ||
) | ||
|
||
const lineStyle = React.useMemo(() => StyleSheet.absoluteFillObject, []) | ||
|
||
const animatedStyle = useAnimatedStyle(() => ({ | ||
transform: [{ translateX: interpolate(x.value, [0, 1], [-width, width]) }], | ||
})) | ||
|
||
return ( | ||
<View style={[containerStyle, style]} {...props}> | ||
<AnimatedLinearGradient | ||
colors={[ | ||
backgroundColor || isDarkMode ? colors.gray.grey_08 : colors.gray.grey_02, | ||
gradientColor || isDarkMode ? colors.gray.grey_06 : colors.gray.grey_01, | ||
backgroundColor || isDarkMode ? colors.gray.grey_08 : colors.gray.grey_02, | ||
]} | ||
style={[animatedStyle, lineStyle]} | ||
start={{ x: 0, y: 0 }} | ||
end={{ x: 1, y: 0 }} | ||
/> | ||
{children} | ||
</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
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
104 changes: 104 additions & 0 deletions
104
src/features/list-memories/list-memories-all/skeleton.tsx
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,104 @@ | ||
import { useColorScheme } from "react-native" | ||
import { View } from "../../../components/Themed" | ||
import { Skeleton } from "../../../components/skeleton" | ||
import { colors } from "../../../layout/constants/colors" | ||
import sizes from "../../../layout/constants/sizes" | ||
|
||
export function ListMemoriesAllSkeleton() { | ||
const isDarkMode = useColorScheme() === "dark" | ||
const container = { | ||
paddingTop: sizes.paddings["1sm"] * 0.5, | ||
width: sizes.screens.width, | ||
alignItems: "center", | ||
justifyContent: "flex-start", | ||
} | ||
|
||
const memory = { | ||
width: sizes.moment.tiny.width * 0.8, | ||
} | ||
|
||
const header = { | ||
width: sizes.screens.width, | ||
height: sizes.headers.height * 0.6, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
flexDirection: "row", | ||
paddingHorizontal: sizes.margins["1md"], | ||
} | ||
return ( | ||
<View style={container}> | ||
<View style={header}> | ||
<View style={{ flex: 1 }}> | ||
<Skeleton.View style={{ width: 100, height: 16, borderRadius: 10 }} /> | ||
</View> | ||
<Skeleton.View style={{ width: 40, height: 16, borderRadius: 10 }} /> | ||
</View> | ||
<View | ||
style={{ | ||
flexDirection: "row", | ||
width: sizes.screens.width, | ||
paddingTop: sizes.paddings["1sm"], | ||
paddingBottom: sizes.paddings["1lg"], | ||
marginBottom: sizes.margins["1sm"], | ||
borderBottomWidth: 1, | ||
borderColor: isDarkMode ? colors.gray.grey_08 : colors.gray.grey_02, | ||
}} | ||
> | ||
<View style={[memory, { marginLeft: sizes.margins["2sm"] }]}> | ||
<Skeleton.View | ||
style={{ | ||
width: sizes.moment.tiny.width * 0.8, | ||
height: sizes.moment.tiny.height * 0.8, | ||
borderRadius: sizes.moment.tiny.borderRadius * 0.8, | ||
}} | ||
/> | ||
<Skeleton.View | ||
style={{ | ||
alignSelf: "center", | ||
width: 70, | ||
height: 16, | ||
borderRadius: 10, | ||
marginTop: sizes.margins["2sm"], | ||
}} | ||
/> | ||
</View> | ||
<View style={[memory, { marginLeft: sizes.margins["2sm"] }]}> | ||
<Skeleton.View | ||
style={{ | ||
width: sizes.moment.tiny.width * 0.8, | ||
height: sizes.moment.tiny.height * 0.8, | ||
borderRadius: sizes.moment.tiny.borderRadius * 0.8, | ||
}} | ||
/> | ||
<Skeleton.View | ||
style={{ | ||
alignSelf: "center", | ||
width: 70, | ||
height: 16, | ||
borderRadius: 10, | ||
marginTop: sizes.margins["2sm"], | ||
}} | ||
/> | ||
</View> | ||
<View style={[memory, { marginLeft: sizes.margins["2sm"] }]}> | ||
<Skeleton.View | ||
style={{ | ||
width: sizes.moment.tiny.width * 0.8, | ||
height: sizes.moment.tiny.height * 0.8, | ||
borderRadius: sizes.moment.tiny.borderRadius * 0.8, | ||
}} | ||
/> | ||
<Skeleton.View | ||
style={{ | ||
alignSelf: "center", | ||
width: 70, | ||
height: 16, | ||
borderRadius: 10, | ||
marginTop: sizes.margins["2sm"], | ||
}} | ||
/> | ||
</View> | ||
</View> | ||
</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
Oops, something went wrong.