-
Notifications
You must be signed in to change notification settings - Fork 734
fix hint animation #1363
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
fix hint animation #1363
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4084a59
fix hint animation
mendyEdri 876ca41
fix android error
mendyEdri a46173b
Merge branch 'master' into fix/hint-animation
mendyEdri 721c588
Fix android tapping issue + remove hint on animation done
mendyEdri 3fea5a5
typing
mendyEdri cd2cad2
lint
mendyEdri 5663a13
Fix iOS behaviour
mendyEdri ec43535
typing
mendyEdri a066e45
Fix removal after animation timing
mendyEdri f8c51d3
removed log
mendyEdri 84cbf2a
Using now a single toggle to remove Hint component when hidden
mendyEdri 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 |
---|---|---|
|
@@ -146,6 +146,7 @@ export interface HintProps { | |
interface HintState { | ||
targetLayout?: HintTargetFrame; | ||
targetLayoutInWindow?: HintTargetFrame; | ||
animationEnded: boolean; | ||
} | ||
|
||
/** | ||
|
@@ -165,24 +166,38 @@ class Hint extends Component<HintProps, HintState> { | |
|
||
targetRef: ElementRef<typeof RNView> | null = null; | ||
hintRef: ElementRef<typeof RNView> | null = null; | ||
animationDuration = 170; | ||
|
||
state = { | ||
targetLayoutInWindow: undefined, | ||
targetLayout: this.props.targetFrame | ||
targetLayout: this.props.targetFrame, | ||
animationEnded: false | ||
}; | ||
|
||
visibleAnimated = new Animated.Value(Number(!!this.props.visible)); | ||
|
||
componentDidUpdate(prevProps: HintProps) { | ||
if (prevProps.visible !== this.props.visible) { | ||
Animated.timing(this.visibleAnimated, { | ||
toValue: Number(!!this.props.visible), | ||
duration: 170, | ||
useNativeDriver: true | ||
}).start(); | ||
this.animateHint(); | ||
} | ||
} | ||
|
||
animateHint = () => { | ||
Animated.timing(this.visibleAnimated, { | ||
toValue: Number(!!this.props.visible), | ||
duration: this.animationDuration, | ||
useNativeDriver: true | ||
}).start(this.toggleAnimationEndedToRemoveHint); | ||
}; | ||
|
||
toggleAnimationEndedToRemoveHint = () => { | ||
this.setState({animationEnded: true}, () => { | ||
setTimeout(() => { | ||
this.setState({animationEnded: false}); | ||
}, this.animationDuration); | ||
}); | ||
}; | ||
|
||
focusAccessibilityOnHint = () => { | ||
const {message} = this.props; | ||
const targetRefTag = findNodeHandle(this.targetRef); | ||
|
@@ -444,13 +459,10 @@ class Hint extends Component<HintProps, HintState> { | |
renderHint() { | ||
const {onPress, testID} = this.props; | ||
const opacity = onPress ? 0.9 : 1.0; | ||
const Container = onPress ? TouchableOpacity : View; | ||
|
||
|
||
if (this.showHint) { | ||
return ( | ||
<Container | ||
activeOpacity={opacity} | ||
onPress={onPress} | ||
<View | ||
animated | ||
style={[ | ||
{width: this.containerWidth}, | ||
|
@@ -462,19 +474,23 @@ class Hint extends Component<HintProps, HintState> { | |
pointerEvents="box-none" | ||
testID={testID} | ||
> | ||
<TouchableOpacity activeOpacity={opacity} onPress={onPress}> | ||
{this.renderContent()} | ||
</TouchableOpacity> | ||
{this.renderHintTip()} | ||
{this.renderContent()} | ||
</Container> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
renderHintContainer() { | ||
const {style, testID, ...others} = this.props; | ||
const {style, ...others} = this.props; | ||
return ( | ||
<View | ||
{...others} | ||
testID={`${testID}.container`} | ||
// this view must be collapsable, don't pass testID or backgroundColor etc'. | ||
collapsable | ||
testID={undefined} | ||
style={[styles.container, style, this.getContainerPosition()]} | ||
> | ||
{this.renderHint()} | ||
|
@@ -496,9 +512,9 @@ class Hint extends Component<HintProps, HintState> { | |
} | ||
|
||
render() { | ||
const {visible, onBackgroundPress, testID} = this.props; | ||
|
||
if (!visible) { | ||
const {onBackgroundPress, testID} = this.props; | ||
if (!this.props.visible && this.state.animationEnded) { | ||
console.log('removed'); | ||
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. You forgot a console.log (: |
||
return this.props.children; | ||
} | ||
|
||
|
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.
This forces us to trigger two setState calls every time we trigger the animation. twice on enter twice on exit.
Maybe we can reduce that..
If you think about it, while the Hint is visible it doesn't matter really what's the value of
animationEnded
state.What if instead of keeping
animationEnded
you'll keep something else, likeactuallyVisible
,hasUnmounted
(or anything with a better name (: )Then you'll update it once on enter and once on exit...
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.
Right, fixed