-
Notifications
You must be signed in to change notification settings - Fork 612
feat: skeleton 骨架屏 #1465
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
Merged
Merged
feat: skeleton 骨架屏 #1465
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16bb6dd
feat: skeleton 骨架屏
qrliu97 dcd7ccd
chore: AI review 意见采纳
qrliu97 738c7c7
feat: 添加Skeleton.Provider组件
mymysmossne 9447503
merge
mymysmossne 1bf83a0
feat: 重构动画
1uokun 1509f4f
Merge official 5.5.0 branch
1uokun baefa91
fix: add skeletonShimmer
1uokun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 @@ | ||
| import { StyleProp, ViewStyle } from 'react-native' | ||
| import { SkeletonStyle } from './style' | ||
|
|
||
| export interface SkeletonProps { | ||
| animated?: boolean | ||
| style?: StyleProp<ViewStyle> | ||
| styles?: Partial<SkeletonStyle> | ||
| } | ||
|
|
||
| export type SkeletonTitleProps = SkeletonProps | ||
|
|
||
| export interface SkeletonParagraphProps extends SkeletonProps { | ||
| lineCount?: number | ||
| } |
This file contains hidden or 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,62 @@ | ||
| import React, { useEffect, useRef } from 'react' | ||
| import { Animated, StyleProp, View, ViewStyle } from 'react-native' | ||
| import { useTheme } from '../style' | ||
| import { SkeletonProps } from './PropsType' | ||
| import SkeletonStyles from './style' | ||
|
|
||
| // Animated skeleton component | ||
| const AnimatedSkeleton: React.FC<{ | ||
| style?: StyleProp<ViewStyle> | ||
| animated?: boolean | ||
| }> = ({ style, animated }) => { | ||
| const opacityValue = useRef(new Animated.Value(0)).current | ||
|
|
||
| useEffect(() => { | ||
| if (animated) { | ||
| const animation = Animated.loop( | ||
| Animated.timing(opacityValue, { | ||
| toValue: 1, | ||
| duration: 1500, | ||
| useNativeDriver: true, | ||
| }), | ||
| ) | ||
| animation.start() | ||
| return () => { | ||
| animation.stop() | ||
| opacityValue.setValue(0) | ||
| } | ||
| } | ||
| }, [animated, opacityValue]) | ||
|
|
||
| if (animated) { | ||
| const opacity = opacityValue.interpolate({ | ||
| inputRange: [0, 0.5, 1], | ||
| outputRange: [1, 0.25, 1], | ||
| }) | ||
| return <Animated.View style={[style, { opacity }]} /> | ||
| } | ||
|
|
||
| return <View style={style} /> | ||
| } | ||
|
|
||
| const InternalSkeleton: React.FC<SkeletonProps> = (props) => { | ||
| const { animated, style, styles: customStyles, ...restProps } = props | ||
| const themeStyles = useTheme({ | ||
| styles: customStyles, | ||
| themeStyles: SkeletonStyles, | ||
| }) | ||
|
|
||
| return ( | ||
| <AnimatedSkeleton | ||
| style={[themeStyles.skeleton, style]} | ||
| animated={animated} | ||
| {...restProps} | ||
| /> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| ) | ||
| } | ||
|
|
||
| const Skeleton = React.memo(InternalSkeleton) as typeof InternalSkeleton | ||
|
|
||
| Skeleton.displayName = 'Skeleton' | ||
|
|
||
| export default Skeleton | ||
This file contains hidden or 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,49 @@ | ||
| import React from 'react' | ||
| import { View } from 'react-native' | ||
| import { useTheme } from '../style' | ||
| import { SkeletonParagraphProps } from './PropsType' | ||
| import InternalSkeleton from './Skeleton' | ||
| import SkeletonStyles from './style' | ||
|
|
||
| const InternalSkeletonParagraph: React.FC<SkeletonParagraphProps> = (props) => { | ||
| const { | ||
| animated, | ||
| lineCount = 4, | ||
| style, | ||
| styles: customStyles, | ||
| ...restProps | ||
| } = props | ||
|
|
||
| const themeStyles = useTheme({ | ||
| styles: customStyles, | ||
| themeStyles: SkeletonStyles, | ||
| }) | ||
|
|
||
| const _lineCount = typeof lineCount === 'number' ? Math.max(lineCount, 1) : 4 | ||
|
lqr131115 marked this conversation as resolved.
Outdated
|
||
| return ( | ||
| <View style={[themeStyles.skeletonParagraph, style]} {...restProps}> | ||
| {Array.from({ length: _lineCount }).map((_, index) => { | ||
| const isLastLine = index === _lineCount - 1 | ||
| return ( | ||
| <InternalSkeleton | ||
| key={index} | ||
| animated={animated} | ||
| style={[ | ||
| themeStyles.skeletonParagraphLine, | ||
| isLastLine && themeStyles.skeletonParagraphLastLine, | ||
| ]} | ||
| styles={customStyles} | ||
| /> | ||
| ) | ||
| })} | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| const SkeletonParagraph = React.memo( | ||
| InternalSkeletonParagraph, | ||
| ) as typeof InternalSkeletonParagraph | ||
|
|
||
| SkeletonParagraph.displayName = 'SkeletonParagraph' | ||
|
|
||
| export default SkeletonParagraph | ||
This file contains hidden or 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,31 @@ | ||
| import React from 'react' | ||
| import { useTheme } from '../style' | ||
| import { SkeletonTitleProps } from './PropsType' | ||
| import InternalSkeleton from './Skeleton' | ||
| import SkeletonStyles from './style' | ||
|
|
||
| const InternalSkeletonTitle: React.FC<SkeletonTitleProps> = (props) => { | ||
| const { animated, style, styles: customStyles, ...restProps } = props | ||
|
|
||
| const themeStyles = useTheme({ | ||
| styles: customStyles, | ||
| themeStyles: SkeletonStyles, | ||
| }) | ||
|
|
||
| return ( | ||
| <InternalSkeleton | ||
| animated={animated} | ||
| style={[themeStyles.skeletonTitle, style]} | ||
| styles={customStyles} | ||
| {...restProps} | ||
| /> | ||
| ) | ||
| } | ||
|
lqr131115 marked this conversation as resolved.
|
||
|
|
||
| const SkeletonTitle = React.memo( | ||
| InternalSkeletonTitle, | ||
| ) as typeof InternalSkeletonTitle | ||
|
|
||
| SkeletonTitle.displayName = 'SkeletonTitle' | ||
|
|
||
| export default SkeletonTitle | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.