Skip to content
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

Broken DrawerLaytout with useNativeAnimations = true #2707

Closed
Smoovsky opened this issue Dec 21, 2023 · 1 comment
Closed

Broken DrawerLaytout with useNativeAnimations = true #2707

Smoovsky opened this issue Dec 21, 2023 · 1 comment
Labels
Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided

Comments

@Smoovsky
Copy link

Smoovsky commented Dec 21, 2023

Description

When the drawer opening animation is playing, if you hit the overlay to close the drawer, the display will stuck as the drawer is opened after the drawer closing animation is finished.
drawerLayout

This is reproducible on various Android devices and iPhones (though all only tested with Expo Go).

When this bug occurs, the component's state and subcomponents' prop appear to be correct, i.e. the drawerStyle has correct translateX, but it just won't render correctly.

It could be get around by removing the animation at all:

    // Line:492, react-native-gesture-handler\src\components\DrawerLayout.tsx

    // Animated.spring(this.state.drawerTranslation, {
    //   velocity,
    //   bounciness: 0,
    //   toValue,
    //   useNativeDriver: this.props.useNativeAnimations!,
    //   speed: speed ?? undefined,
    // }).start(({ finished }) => {
    //   if (finished) {
        this.emitStateChanged(IDLE, willShow);
        this.setState({ drawerOpened: willShow });
        if (this.state.drawerState !== DRAGGING) {
          // it's possilbe that user started drag while the drawer
          // was settling, don't override state in this case
          this.setState({ drawerState: IDLE });
        }
        if (willShow) {
          this.props.onDrawerOpen?.();
        } else {
          this.props.onDrawerClose?.();
        }
      // }
    // });

Setting useNativeAnimations={false} when initializing <DrawerLayout /> could also get around with this.

Steps to reproduce

  1. create-expo-app with the blank template
  2. expo install react-native-gesture-handler
  3. App.js:
import { Pressable, Text, View } from 'react-native';
import { useRef } from 'react';
import DrawerLayout from 'react-native-gesture-handler/DrawerLayout';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

handleDrawerSlide = (status) => {
  // outputs a value between 0 and 1
  console.log(status);
};

renderDrawer = () => {
  return (
    <View>
      <Text>I am in the drawer!</Text>
    </View>
  );
};

export default Drawerable = () => {

  const drawer = useRef(null);

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <View style={{ flex: 1 }}>
        <DrawerLayout
          // get around by setting useNativeAnimations={false} (which is true by default)
          // useNativeAnimations={false}
          ref={drawer}
          drawerWidth={200}
          drawerPosition={DrawerLayout.positions.Right}
          drawerType="front"
          drawerBackgroundColor="#ddd"
          renderNavigationView={renderDrawer}
          onDrawerSlide={handleDrawerSlide}>
          <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
            <Pressable onPress={() => drawer.current?.openDrawer()}>
              <Text>Hello, it's me</Text>
            </Pressable>
          </View>
        </DrawerLayout>
      </View>
    </GestureHandlerRootView>
  );
}

Snack or a link to a repository

https://snack.expo.dev/@smokovsky/drawertest

Gesture Handler version

2.12.0

React Native version

0.72.6

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

Expo managed workflow

Architecture

None

Build type

None

Device

Real device

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Repro provided A reproduction with a snack or repo is provided Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS labels Dec 21, 2023
@Smoovsky
Copy link
Author

Duplicated as #2208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

No branches or pull requests

1 participant