From 22f886525abef4dfc2f213cf3cd6a9d4c56070c4 Mon Sep 17 00:00:00 2001 From: code-lover-jarvis <77064989+code-lover-jarvis@users.noreply.github.com> Date: Fri, 3 Dec 2021 20:27:12 +0530 Subject: [PATCH] Update SlideButton.js there were warnings related to useNativeDriver and componentWillMount, both were cleared. --- SlideButton.js | 52 +++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/SlideButton.js b/SlideButton.js index e0b3fdb..44d702e 100644 --- a/SlideButton.js +++ b/SlideButton.js @@ -8,9 +8,13 @@ import { Image, TouchableHighlight, PanResponder, + Dimensions, Animated } from 'react-native'; +var SCREEN_WIDTH = Dimensions.get('window').width; +var SCREEN_HEIGHT = Dimensions.get('window').height; + export var SlideDirection = { LEFT: "left", RIGHT: "right", @@ -31,18 +35,16 @@ export class SlideButton extends Component { }; } - /* Button movement of > 40% is considered a successful slide by default*/ + /* Button movement of > 40% is considered a successful slide */ isSlideSuccessful() { - var slidePercent = this.props.successfulSlidePercent || 40; - var successfulSlideWidth = this.buttonWidth * slidePercent / 100; if (!this.props.slideDirection) { - return this.state.dx > this.props.successfulSlideWidth; // Defaults to right slide + return this.state.dx > (this.buttonWidth * 0.4); // Defaults to right slide } else if (this.props.slideDirection === SlideDirection.RIGHT) { - return this.state.dx > this.props.successfulSlideWidth; + return this.state.dx > (this.buttonWidth * 0.4); } else if (this.props.slideDirection === SlideDirection.LEFT) { - return this.state.dx < (-1 * this.props.successfulSlideWidth); + return this.state.dx < -(this.buttonWidth * 0.4); } else if (this.props.slideDirection === SlideDirection.BOTH) { - return Math.abs(this.state.dx) > this.props.successfulSlideWidth; + return Math.abs(this.state.dx) > (this.buttonWidth * 0.4); } } @@ -52,7 +54,7 @@ export class SlideButton extends Component { } } - componentWillMount() { + UNSAFE_componentWillMount() { var self = this; // TODO: Raise error if slideDirection prop is invalid. @@ -127,6 +129,16 @@ export class SlideButton extends Component { } } + measureButton() { + var self = this; + this.refs.button.measure((ox, oy, width, height) => { + self.setState({ + initialX: ox, + buttonWidth: width + }); + }); + } + moveButtonIn(onCompleteCallback) { var self = this; var startPos = this.state.dx < 0 ? this.state.initialX + this.buttonWidth : @@ -139,7 +151,8 @@ export class SlideButton extends Component { }, () => { Animated.timing( self.state.animatedX, - { toValue: endPos } + { toValue: endPos, + useNativeDriver: false } ).start(onCompleteCallback); }); } @@ -155,7 +168,8 @@ export class SlideButton extends Component { }, () => { Animated.timing( self.state.animatedX, - { toValue: endPos } + { toValue: endPos, + useNativeDriver: false } ).start(onCompleteCallback); }); } @@ -171,7 +185,8 @@ export class SlideButton extends Component { }, () => { Animated.timing( self.state.animatedX, - { toValue: endPos } + { toValue: endPos, + useNativeDriver: false } ).start(onCompleteCallback); }); } @@ -187,7 +202,7 @@ export class SlideButton extends Component { var style = [styles.button, this.props.style, {left: this.state.dx}]; if (this.state.released) { - style = [styles.button, this.props.style, {left: this.state.animatedX}]; + style = [styles.button, this.props.style, { left: this.state.animatedX }]; var button = ( {this.props.children} @@ -197,28 +212,21 @@ export class SlideButton extends Component { var button = ( - {this.props.children} + {this.props.children} ); } return ( - - + { button } - ); } } -SlideButton.propTypes = { - width: React.PropTypes.number.isRequired, - height: React.PropTypes.number.isRequired, - successfulSlidePercent: React.PropTypes.number -}; - const styles = StyleSheet.create({ container: { position: 'relative'