Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
fix: get rid of random red screen on iOS on opening drawer (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
osdnk authored and satya164 committed May 13, 2019
1 parent 6bd22fe commit fa8017e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Object.assign(NativeModules, {
jest.mock('react-native-reanimated', () => ({
__esModule: true,
default: {
Code: () => null,
View: require('react-native').Animated.View,
Text: require('react-native').Animated.Text,
Clock: jest.fn(),
Expand Down
29 changes: 20 additions & 9 deletions src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default class DrawerView extends React.PureComponent<Props> {

private isStatusBarHidden: boolean = false;

private isSpringManuallyTriggered = new Value<Binary>(FALSE);
private manuallyTriggerSpring = new Value<Binary>(FALSE);

private transitionTo = (isOpen: number | Animated.Node<number>) => {
const toValue = new Value(0);
Expand Down Expand Up @@ -349,7 +349,7 @@ export default class DrawerView extends React.PureComponent<Props> {
cond(
eq(this.gestureState, State.ACTIVE),
[
set(this.isSpringManuallyTriggered, FALSE),
set(this.manuallyTriggerSpring, FALSE),
cond(this.isSwiping, NOOP, [
// We weren't dragging before, set it to true
set(this.isSwiping, TRUE),
Expand All @@ -369,7 +369,7 @@ export default class DrawerView extends React.PureComponent<Props> {
set(this.touchX, 0),
this.transitionTo(
cond(
this.isSpringManuallyTriggered,
this.manuallyTriggerSpring,
this.isOpen,
cond(
or(
Expand Down Expand Up @@ -429,7 +429,7 @@ export default class DrawerView extends React.PureComponent<Props> {
nativeEvent,
}: TapGestureHandlerStateChangeEvent) => {
if (nativeEvent.oldState === State.ACTIVE && !this.props.locked) {
this.toggleDrawer(false);
this.manuallyTriggerSpring.setValue(TRUE);
}
};

Expand All @@ -447,12 +447,13 @@ export default class DrawerView extends React.PureComponent<Props> {
};

private toggleDrawer = (open: boolean) => {
this.nextIsOpen.setValue(open ? TRUE : FALSE);
this.isSpringManuallyTriggered.setValue(TRUE);
if (this.currentOpenValue !== open) {
this.nextIsOpen.setValue(open ? TRUE : FALSE);

// This value will also be set shortly after as changing this.nextIsOpen changes this.isOpen
// However, there's a race condition on Android, so we need to set a bit earlier
this.currentOpenValue = open;
// This value will also be set shortly after as changing this.nextIsOpen changes this.isOpen
// However, there's a race condition on Android, so we need to set a bit earlier
this.currentOpenValue = open;
}
};

private toggleStatusBar = (hidden: boolean) => {
Expand Down Expand Up @@ -546,6 +547,16 @@ export default class DrawerView extends React.PureComponent<Props> {
/>
</TapGestureHandler>
</Animated.View>
<Animated.Code
exec={block([
onChange(this.manuallyTriggerSpring, [
cond(eq(this.manuallyTriggerSpring, TRUE), [
set(this.nextIsOpen, FALSE),
call([], () => (this.currentOpenValue = false)),
]),
]),
])}
/>
<Animated.View
accessibilityViewIsModal={open}
removeClippedSubviews={Platform.OS !== 'ios'}
Expand Down

0 comments on commit fa8017e

Please sign in to comment.