This repository was archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 168
Implement small spinner #377
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f1342cd
Implement small spinner
valentinewallace 3359a02
Use regular purple in spinner
tanx 7159b07
Inherit props
tanx ce9e51d
Add scaling for small spinner
valentinewallace 32f4d7a
V1 of timed spinner
valentinewallace 8f2fcfa
Implement spinner for loading network using svgs
valentinewallace e73dd09
Modularize gradient
valentinewallace 4ead478
Wrap and re-export svgs package
valentinewallace 20a55e8
Add optional style prop to medium spinner
valentinewallace fd3a9c2
Fix linting
valentinewallace c3e9674
Update package-lock.json
tanx eed252d
Re-export all svgs name spaces generically
tanx 13344f8
Fix component import paths
tanx 770e67e
Break progress path and spinner fill into components
valentinewallace 6e8db2b
Make spinner reuseable for OpenChannels
valentinewallace 7a2b913
Remove style param for LoadNetworkSpinner
valentinewallace 8b06aee
Fix typo
valentinewallace a08b9e9
Decrease small spinner size
tanx b62c998
Decrease network spinner size
tanx af340fb
Fix spaces
tanx 85f5791
Rename SvgJS to Sag
tanx d7b546a
Change storybook styles
valentinewallace 15746e3
Fix storybook decorators
tanx 909edd7
Add missing purple again
tanx 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,210 @@ | ||
| import React from 'react'; | ||
| import { | ||
| ActivityIndicator, | ||
| StyleSheet, | ||
| View, | ||
| ViewPropTypes, | ||
| } from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import { color, font } from './style'; | ||
| import Icon from './icon'; | ||
| import Text from './text'; | ||
| import Svg, { Path, Circle, Defs, Stop, LinearGradient } from './svg'; | ||
|
|
||
| // | ||
| // Small Spinner | ||
| // | ||
|
|
||
| const smallStyles = StyleSheet.create({ | ||
| spinner: { | ||
| transform: [{ scale: 1.0 }], | ||
| }, | ||
| }); | ||
|
|
||
| export const SmallSpinner = ({ ...props }) => ( | ||
| <ActivityIndicator | ||
| size="small" | ||
| color={color.purple} | ||
| style={smallStyles.spinner} | ||
| {...props} | ||
| /> | ||
| ); | ||
|
|
||
| // | ||
| // Load Network Spinner | ||
| // | ||
|
|
||
| const sizeM = 80; | ||
| const progressWidthM = 3; | ||
|
|
||
| const loadNetworkStyles = StyleSheet.create({ | ||
| spinner: { | ||
| margin: 20, | ||
| }, | ||
| bolt: { | ||
| height: 126 / 4.5, | ||
| width: 64 / 4.5, | ||
| }, | ||
| copy: { | ||
| fontSize: font.sizeXS, | ||
| marginTop: 5, | ||
| color: color.white, | ||
| textAlign: 'center', | ||
| }, | ||
| }); | ||
|
|
||
| export const LoadNetworkSpinner = ({ percentage, msg }) => ( | ||
| <View style={loadNetworkStyles.spinner}> | ||
| <ResizeableSpinner | ||
| percentage={percentage} | ||
| size={sizeM} | ||
| progressWidth={progressWidthM} | ||
| gradient="loadNetworkGrad" | ||
| icon="lightning-bolt" | ||
| iconStyles={loadNetworkStyles.bolt} | ||
| /> | ||
| <Text style={loadNetworkStyles.copy}>{msg}</Text> | ||
| </View> | ||
| ); | ||
|
|
||
| LoadNetworkSpinner.propTypes = { | ||
| percentage: PropTypes.number.isRequired, | ||
| msg: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| // | ||
| // Resizeable Spinner | ||
| // | ||
|
|
||
| const resizeableStyles = StyleSheet.create({ | ||
| iconWrapper: { | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| bottom: 0, | ||
| right: 0, | ||
| justifyContent: 'center', | ||
| alignItems: 'center', | ||
| }, | ||
| }); | ||
|
|
||
| const ResizeableSpinner = ({ | ||
| percentage, | ||
| size, | ||
| gradient, | ||
| progressWidth, | ||
| icon, | ||
| iconStyles, | ||
| }) => ( | ||
| <View style={{ width: size, height: size }}> | ||
| <Svg width={size} height={size}> | ||
| <Gradients /> | ||
| <SpinnerProgress | ||
| width={size} | ||
| percentage={percentage} | ||
| color={`url(#${gradient})`} | ||
| /> | ||
| { | ||
| <SpinnerFill | ||
| spinnerWidth={size} | ||
| progressWidth={progressWidth} | ||
| color={color.blackDark} | ||
| /> | ||
| } | ||
| </Svg> | ||
| <View style={resizeableStyles.iconWrapper}> | ||
| <Icon image={icon} style={iconStyles} /> | ||
| </View> | ||
| </View> | ||
| ); | ||
|
|
||
| ResizeableSpinner.propTypes = { | ||
| percentage: PropTypes.number.isRequired, | ||
| size: PropTypes.number.isRequired, | ||
| progressWidth: PropTypes.number.isRequired, | ||
| gradient: PropTypes.string.isRequired, | ||
| icon: PropTypes.string.isRequired, | ||
| iconStyles: ViewPropTypes.style, | ||
| }; | ||
|
|
||
| // | ||
| // Loading Network Gradient | ||
| // | ||
|
|
||
| const Gradients = () => ( | ||
| <Defs> | ||
| <LinearGradient id="loadNetworkGrad" x1="0" y1="0" x2="1" y2="1"> | ||
| <Stop offset="0%" stopColor={color.loadNetworkLightPurple} /> | ||
| <Stop offset="50%" stopColor={color.loadNetworkMedPurple} /> | ||
| <Stop offset="70%" stopColor={color.loadNetworkMedDarkPurple} /> | ||
| <Stop offset="100%" stopColor={color.purple} /> | ||
| </LinearGradient> | ||
| <LinearGradient id="openChannelsGrad" x1="0" y1="0" x2="1" y2="1"> | ||
| <Stop offset="0%" stopColor={color.openChansLightPurple} /> | ||
| <Stop offset="50%" stopColor={color.openChansDarkPurple} /> | ||
| </LinearGradient> | ||
| </Defs> | ||
| ); | ||
|
|
||
| // | ||
| // Spinner Progress Path | ||
| // | ||
|
|
||
| const SpinnerProgress = ({ width, percentage, color }) => ( | ||
| <Path | ||
| d={`M${width / 2} ${width / 2} L${width / 2} 0 ${generateArc( | ||
| percentage, | ||
| width / 2 | ||
| )} Z`} | ||
| fill={color} | ||
| /> | ||
| ); | ||
|
|
||
| SpinnerProgress.propTypes = { | ||
| width: PropTypes.number.isRequired, | ||
| percentage: PropTypes.number.isRequired, | ||
| color: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| // | ||
| // Spinner Fill | ||
| // | ||
|
|
||
| const SpinnerFill = ({ spinnerWidth, progressWidth, color }) => ( | ||
| <Circle | ||
| cx={spinnerWidth / 2} | ||
| cy={spinnerWidth / 2} | ||
| r={spinnerWidth / 2 - progressWidth} | ||
| fill={color} | ||
| /> | ||
| ); | ||
|
|
||
| SpinnerFill.propTypes = { | ||
| spinnerWidth: PropTypes.number.isRequired, | ||
| progressWidth: PropTypes.number.isRequired, | ||
| color: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| const generateArc = (percentage, radius) => { | ||
| if (percentage === 0) { | ||
| percentage = 1; | ||
| } else if (percentage === 100) { | ||
| percentage = 99.999; | ||
| } | ||
| const a = percentage * 2 * Math.PI / 100; // angle (in radian) depends on percentage | ||
| const r = radius; // radius of the circle | ||
| var rx = r, | ||
| ry = r, | ||
| xAxisRotation = 0, | ||
| largeArcFlag = 1, | ||
| sweepFlag = 1, | ||
| x = r + r * Math.sin(a), | ||
| y = r - r * Math.cos(a); | ||
| if (percentage <= 50) { | ||
| largeArcFlag = 0; | ||
| } else { | ||
| largeArcFlag = 1; | ||
| } | ||
|
|
||
| return `A${rx} ${ry} ${xAxisRotation} ${largeArcFlag} ${sweepFlag} ${x} ${y}`; | ||
| }; |
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,3 @@ | ||
| import Svg from 'svgs'; | ||
| export default Svg; | ||
| export * from 'svgs'; |
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,24 @@ | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import MainContent from '../../src/component/main-content'; | ||
| import { LoadNetworkSpinner, SmallSpinner } from '../../src/component/spinner'; | ||
| import { color } from '../../src/component/style'; | ||
| import Background from '../../src/component/background'; | ||
|
|
||
| storiesOf('Spinner', module) | ||
| .addDecorator(story => ( | ||
| <MainContent style={{ justifyContent: 'center' }}>{story()}</MainContent> | ||
| )) | ||
| .add('SmallSpinner', () => <SmallSpinner />); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to set height/width via the |
||
|
|
||
| storiesOf('Spinner', module) | ||
| .addDecorator(story => ( | ||
| <Background color={color.blackDark}>{story()}</Background> | ||
| )) | ||
| .add('LoadNetworkSpinner', () => ( | ||
| <MainContent style={{ alignItems: 'flex-start', flexDirection: 'row' }}> | ||
| <LoadNetworkSpinner percentage={30} msg="Loading network..." /> | ||
| <LoadNetworkSpinner percentage={50} msg="Almost done..." /> | ||
| <LoadNetworkSpinner percentage={100} msg="Just a few seconds..." /> | ||
| </MainContent> | ||
| )); | ||
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.
Seems like the package-lock.json shouldn’t change so much here. Which node/npm version are you using? We should stick with the current LTS node@8.x/npm@5.x since newer versions of npm will rebuild the package-lock.json and potentially cause incompapatibilites on travis.
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.
Gotcha, i'll switch versions