Skip to content

Commit cbe7e33

Browse files
authored
AnimatedScanner - adding 'containerStyle' prop (#981)
1 parent 7b0908a commit cbe7e33

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

demo/src/screens/componentScreens/CardScannerScreen.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
import React, {Component} from 'react';
2-
import {StyleSheet} from 'react-native';
3-
import {View, Assets, Constants, Card, Button, Colors, Typography, Text, AnimatedScanner} from 'react-native-ui-lib'; //eslint-disable-line
2+
import {View, Card, Button, Colors, Text, AnimatedScanner} from 'react-native-ui-lib'; //eslint-disable-line
43
import posts from '../../data/posts';
54

5+
66
const featureIcon = require('../../assets/icons/star.png');
77
const shareIcon = require('../../assets/icons/share.png');
88

99
export default class CardScannerScreen extends Component {
1010
constructor(props) {
1111
super(props);
1212

13-
this.start = this.start.bind(this);
14-
this.reset = this.reset.bind(this);
15-
this.onBreak = this.onBreak.bind(this);
16-
1713
this.state = {
1814
progress: 0,
1915
started: false,
2016
reset: false,
21-
isDone: false,
17+
isDone: false
2218
};
2319
}
2420

25-
onBreak({isDone}) {
21+
onBreak = ({isDone}) => {
2622
if (!isDone) {
2723
this.start();
2824
} else {
29-
this.setState({
30-
isDone,
31-
});
25+
this.setState({isDone});
3226
}
3327
}
3428

35-
start() {
29+
start = () => {
3630
const {progress} = this.state;
31+
3732
this.setState({
3833
started: true,
3934
reset: false,
40-
progress: progress + 25,
35+
progress: progress + 25
4136
});
4237
}
4338

44-
reset() {
39+
reset = () => {
4540
this.setState({
4641
started: false,
4742
progress: 0,
4843
reset: true,
49-
isDone: false,
44+
isDone: false
5045
});
5146
}
5247

5348
render() {
5449
const {reset} = this.state;
5550
const post = posts[0];
5651
const statusColor = post.status === 'Published' ? Colors.green30 : Colors.orange30;
52+
5753
return (
5854
<View flex useSafeArea>
5955
<View flex padding-20>
60-
<View paddingL-40 height={6} width={'100%'} bg-violet50 marginB-20>
61-
<AnimatedScanner backgroundColor={Colors.purple30} progress={98} duration={1600} />
56+
<View paddingL-40 marginB-20>
57+
<AnimatedScanner
58+
backgroundColor={Colors.purple30}
59+
progress={98} duration={1600}
60+
containerStyle={{backgroundColor: Colors.violet50, height: 6}}
61+
/>
6262
</View>
6363

6464
<Card containerStyle={{marginBottom: 15}} onPress={() => console.log('press on a card')}>
65-
<Card.Image height={115} imageSource={post.coverImage} />
65+
<Card.Image height={115} source={post.coverImage}/>
6666
<View padding-20>
6767
<Text text40 color={Colors.dark10}>
6868
{post.title}
@@ -80,8 +80,8 @@ export default class CardScannerScreen extends Component {
8080
{post.likes} Likes
8181
</Text>
8282
<View row spread>
83-
<Button style={{marginRight: 10}} text90 link iconSource={featureIcon} label="Feature" />
84-
<Button text90 link iconSource={shareIcon} label="Share" />
83+
<Button style={{marginRight: 10}} text90 link iconSource={featureIcon} label="Feature"/>
84+
<Button text90 link iconSource={shareIcon} label="Share"/>
8585
</View>
8686
</View>
8787

@@ -107,8 +107,8 @@ export default class CardScannerScreen extends Component {
107107
</View>
108108

109109
<View row center padding-20>
110-
<Button size="medium" label="Reset" onPress={this.reset} disabled={!this.state.isDone} />
111-
<Button marginL-10 size="medium" label="Publish" onPress={this.start} disabled={this.state.started} />
110+
<Button size="medium" label="Reset" onPress={this.reset} disabled={!this.state.isDone}/>
111+
<Button marginL-10 size="medium" label="Publish" onPress={this.start} disabled={this.state.started}/>
112112
</View>
113113
</View>
114114
);

src/components/animatedScanner/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import _ from 'lodash';
22
import PropTypes from 'prop-types';
33
import React from 'react';
4-
import {StyleSheet, Animated} from 'react-native';
4+
import {ViewPropTypes, StyleSheet, Animated} from 'react-native';
55
import {Colors} from '../../style';
66
import {BaseComponent} from '../../commons';
77
import View from '../../components/view';
88

9+
910
// TODO: add finisher animation (check icon animation or something)
1011
/**
1112
* @description: Scanner component for progress indication
@@ -40,7 +41,11 @@ export default class AnimatedScanner extends BaseComponent {
4041
/**
4142
* should hide the scanner line
4243
*/
43-
hideScannerLine: PropTypes.bool
44+
hideScannerLine: PropTypes.bool,
45+
/**
46+
* the container style
47+
*/
48+
containerStyle: ViewPropTypes.style
4449
};
4550

4651
static defaultProps = {
@@ -59,6 +64,7 @@ export default class AnimatedScanner extends BaseComponent {
5964

6065
componentDidMount() {
6166
const {progress, duration} = this.props;
67+
6268
if (progress > 0) {
6369
this.animate(progress, duration);
6470
}
@@ -70,6 +76,7 @@ export default class AnimatedScanner extends BaseComponent {
7076

7177
componentDidUpdate(prevProps) {
7278
const {progress, duration} = this.props;
79+
7380
if (prevProps.progress !== progress) {
7481
this.animate(progress, duration);
7582
}
@@ -81,26 +88,26 @@ export default class AnimatedScanner extends BaseComponent {
8188

8289
animate(toValue, duration) {
8390
const {animatedProgress} = this.state;
91+
8492
Animated.timing(animatedProgress, {
8593
toValue,
8694
duration,
8795
useNativeDriver: false
8896
}).start(({finished}) => {
8997
if (finished) {
9098
const isDone = toValue >= 100;
91-
this.setState({
92-
isDone
93-
});
99+
this.setState({isDone});
94100
_.invoke(this.props, 'onBreakpoint', {progress: toValue, isDone});
95101
}
96102
});
97103
}
98104

99105
render() {
100-
const {opacity, backgroundColor, hideScannerLine, style} = this.props;
106+
const {opacity, backgroundColor, hideScannerLine, style, containerStyle} = this.props;
101107
const {isDone, animatedProgress} = this.state;
108+
102109
return (
103-
<View style={{...StyleSheet.absoluteFillObject}}>
110+
<View style={[{...StyleSheet.absoluteFillObject}, containerStyle]}>
104111
<Animated.View
105112
style={[
106113
this.styles.container,

0 commit comments

Comments
 (0)