-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
New skeleton loader for LHN #14456
Merged
Merged
New skeleton loader for LHN #14456
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0c38b1b
show skeleton instead of activity indicator while loading the app
bernhardoj a430364
only show back button on small screen
bernhardoj ea87754
move around the loading state
bernhardoj 5a93cec
fix lint
bernhardoj 3574120
fix lint
bernhardoj 60011ae
update skeleton line position
bernhardoj f2f5c25
set the params to the specific route
bernhardoj 27c99ef
fix lint
bernhardoj efbfd4d
undisable header buttons
bernhardoj 9ba9aee
hide new workspace menu while loading
bernhardoj 5fc5921
add animation for popover menu item
bernhardoj 18775b1
remove key
bernhardoj daa31dc
Merge branch 'main' into feat/12698
bernhardoj e7cee56
Merge branch 'main' into feat/12698
bernhardoj 10f2708
Merge branch 'main' into feat/12698
bernhardoj fb4487d
Merge branch 'main' into feat/12698
bernhardoj e396b1b
Merge branch 'main' into feat/12698
bernhardoj 36a6181
fix open report is called on existing report
bernhardoj f07c457
Merge branch 'main' into feat/12698
bernhardoj 733c0f8
add comment
bernhardoj 322d280
Merge branch 'main' into feat/12698
bernhardoj 1e2ff6c
revert animation
bernhardoj 33140fb
fix lint
bernhardoj d8f540c
Merge branch 'main' into feat/12698
bernhardoj 4abf178
fix inconsistent skeleton height
bernhardoj 9f7df79
fix lint
bernhardoj cea7062
Merge branch 'main' into feat/12698
bernhardoj e2f63db
Revert "fix inconsistent skeleton height"
bernhardoj 4b0dbef
fix inconsistent skeleton height
bernhardoj d080b57
use ceil to get the number of skeleton
bernhardoj 22249d2
move the height calculation to the skeleton component
bernhardoj bbc9a66
fix lint
bernhardoj 3a660a5
add comment
bernhardoj 829b20e
change variable name
bernhardoj ad77e83
Merge branch 'main' into feat/12698
bernhardoj 5a8363c
change variable name
bernhardoj 45c2706
Merge branch 'main' into feat/12698
bernhardoj 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 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,97 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import {Rect, Circle} from 'react-native-svg'; | ||
import SkeletonViewContentLoader from 'react-content-loader/native'; | ||
import CONST from '../CONST'; | ||
import themeColors from '../styles/themes/default'; | ||
import styles from '../styles/styles'; | ||
|
||
const propTypes = { | ||
/** Whether to animate the skeleton view */ | ||
shouldAnimate: PropTypes.bool, | ||
}; | ||
|
||
const defaultTypes = { | ||
shouldAnimate: true, | ||
}; | ||
|
||
class LHNSkeletonView extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
skeletonViewItems: [], | ||
}; | ||
} | ||
|
||
/** | ||
* Generate the skeleton view items. | ||
* | ||
* @param {Number} numItems | ||
*/ | ||
generateSkeletonViewItems(numItems) { | ||
if (this.state.skeletonViewItems.length === numItems) { | ||
return; | ||
} | ||
|
||
if (this.state.skeletonViewItems.length > numItems) { | ||
this.setState(prevState => ({ | ||
skeletonViewItems: prevState.skeletonViewItems.slice(0, numItems), | ||
})); | ||
return; | ||
} | ||
|
||
const skeletonViewItems = []; | ||
for (let i = this.state.skeletonViewItems.length; i < numItems; i++) { | ||
const step = i % 3; | ||
let lineWidth; | ||
switch (step) { | ||
case 0: | ||
lineWidth = '100%'; | ||
break; | ||
case 1: | ||
lineWidth = '50%'; | ||
break; | ||
default: | ||
lineWidth = '25%'; | ||
} | ||
skeletonViewItems.push( | ||
<SkeletonViewContentLoader | ||
key={`skeletonViewItems${i}`} | ||
animate={this.props.shouldAnimate} | ||
height={CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT} | ||
backgroundColor={themeColors.borderLighter} | ||
foregroundColor={themeColors.border} | ||
style={styles.mr5} | ||
> | ||
<Circle cx="40" cy="32" r="20" /> | ||
<Rect x="72" y="18" width="20%" height="8" /> | ||
<Rect x="72" y="38" width={lineWidth} height="8" /> | ||
</SkeletonViewContentLoader>, | ||
); | ||
} | ||
|
||
this.setState(prevState => ({ | ||
skeletonViewItems: [...prevState.skeletonViewItems, ...skeletonViewItems], | ||
})); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View | ||
style={styles.flex1} | ||
onLayout={(event) => { | ||
const numItems = Math.ceil(event.nativeEvent.layout.height / CONST.LHN_SKELETON_VIEW_ITEM_HEIGHT); | ||
this.generateSkeletonViewItems(numItems); | ||
}} | ||
> | ||
<View>{this.state.skeletonViewItems}</View> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
LHNSkeletonView.propTypes = propTypes; | ||
LHNSkeletonView.defaultProps = defaultTypes; | ||
|
||
export default LHNSkeletonView; |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bernhardoj, coming from #33163, Is there any specific reason that we didn't render
SkeletonViewContentLoader
directly via anarray map function
here, but pre-calculate and stored inthis.state.skeletonViewItems
inonLayout
callback?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it based on this suggestion. I think it's just for optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bernhardoj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @roryabraham, do you mind sharing the reason why you prefer to generate
skeletonViewItems
and store it in the component's state? In a first glance, I think it's because of optimization as @bernhardoj said above but I usually see the pattern where we generate a list/array of items (with akey
) in component render function, leaving the rendering optimization part for React. ThanksThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ just in case you missed this message @roryabraham
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered here