react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

Drawer gesture / animation sluggish on Android

Open brentvatne opened this issue 8 years ago • 43 comments

Compared to the the DrawerLayout used in react-navigation 2, the one in 3 is reported to feel more sluggish. The change that occurred between these versions is that we now use a drawer implemented with react-native-gesture-handler rather than the built in DrawerLayout, because the built-in one caused all sorts of issues when nesting.

@divisumma and @xanderberkein can you elaborate on what you meant by sluggish with as much detail as possible? Thanks!

brentvatne avatar Nov 26 '18 19:11 brentvatne

Same problem. One crucial reason why I downgraded back down to version 2 until this problem is fixed. The way I experience is that when I use slide gesture to open (not by calling toggleDrawer method), the drawer doesn't open smoothly like version 2 but kind of stops? lags? for very short period of time while opening. Not sure if this happens to all the people

panda0603 avatar Nov 27 '18 07:11 panda0603

cc @kmagiera - maybe time for reanimated

brentvatne avatar Nov 27 '18 20:11 brentvatne

I wrote a minimal app, with just a main screen and a drawer. These two examples share the exact same code, except for the "AppContainer" required by RN3. As you can see, the animation on RN3 stutters visibly.

React Navigation 2: drawerrn2

The code:

const Home   = () => (<View><Text>Home</Text></View>);
const Drawer = () => (<View><Text>Drawer</Text></View>);

const MyDrawer = createDrawerNavigator({
    'Home' : {
        screen : Home
    }
}, {
    contentComponent : Drawer
});

export default class App extends Component<Props> {
    render() {
        return (
            <MyDrawer></MyDrawer>
        );
    }
}

React Navigation 3: drawerrn3

The code:

const Home   = () => (<View><Text>Home</Text></View>);
const Drawer = () => (<View><Text>Drawer</Text></View>);

const MyDrawer = createDrawerNavigator({
    'Home' : {
        screen : Home
    }
}, {
    contentComponent : Drawer
});

const MyContainer = createAppContainer(MyDrawer);

type Props = {};
export default class App extends Component<Props> {
    render() {
        return (
            <MyContainer></MyContainer>
        );
    }
}

package.json

[...]
"react": "16.6.1",
"react-native": "0.57.7",
"react-native-gesture-handler": "^1.0.10",
"react-navigation": "^3.0.2"
[...]

Test results on different devices:

                      RN2      RN3
Samsung Galaxy S6     Good     Bad
Lenovo Zuk Z1         Good     Bad
OnePlus 6             Good     Not so bad
iPhone 6S             Good     Not so bad
iPhone 8              Good     Good, but could be better

divisumma avatar Nov 28 '18 11:11 divisumma

Experiencing same sluggish animation for createMaterialTopTabNavigator between tabs. Reverting back to v2, animation works fine.

neel132-zz avatar Nov 29 '18 10:11 neel132-zz

if you want to you can fork react-navigation-drawer and use the old version rather than the one included in v3. perf is not going to be quite as good for now because we need to switch it to use react-native-reanimated which we will do once we add that as a dependency and switch stack over to it as well

brentvatne avatar Nov 29 '18 21:11 brentvatne

it's possible to improve the performance of the drawer considerably with some optimizations. if someone wants to give it a shot, you can clone the drawer repo and edit this file: https://github.com/react-navigation/react-navigation-drawer/blob/master/src/views/DrawerLayout.js

suggestion via @kmagiera: when the gesture ends we call setState which re-renders drawer along with its children - https://github.com/kmagiera/react-native-gesture-handler/blob/master/DrawerLayout.js#L270. we only do this to update the accessibility and pointerEvents props, so we could use setNativeProps for this instead, similar to https://github.com/react-navigation/react-navigation-stack/blob/master/src/views/StackView/createPointerEventsContainer.js

brentvatne avatar Nov 30 '18 21:11 brentvatne

Also have some issue. Drawer has really ugly animation. Particularly for children routes. In @divisumma example you can see 2 jumps. I see at least 4-5 jumps

My structure like: stack => tabs => stack => drawer

zvs001 avatar Dec 03 '18 12:12 zvs001

@zvs001 - post a new issue and share a repro and an animation. hid your comment because it's off topic as this is about perf

brentvatne avatar Dec 03 '18 17:12 brentvatne

@panda0603 @divisumma

can you test it again with the last version of react-native-gesture-handler ( 1.0.12)? see this commit https://github.com/kmagiera/react-native-gesture-handler/commit/bed9707061e9e70f95a1908fac60d0c544b1e8d9

eriveltonelias avatar Dec 18 '18 12:12 eriveltonelias

Confirm. Same problem

"react": "16.6.3",
"react-native": "0.57.8",
"react-native-gesture-handler": "^1.0.12",
"react-navigation": "^3.0.8",

zunsakai avatar Dec 21 '18 07:12 zunsakai

this is fixed upstream in react-native-gesture-handler and on this branch in drawer: https://github.com/react-navigation/react-navigation-drawer/tree/%40brent/update-rngh

i'm off for holidays but will release this update in the new year

brentvatne avatar Dec 23 '18 01:12 brentvatne

@brentvatne Happy New Year! Are you back from holidays?

i1990jain avatar Jan 07 '19 11:01 i1990jain

yeah i might have time for this later in the week

brentvatne avatar Jan 07 '19 17:01 brentvatne

can you try out [email protected] and let me know if this helps? this includes the upstream changes from react-native-gesture-handler to improve performance.

i haven't tagged this release as latest yet but if a few people confirm that it at least improves their situation then i will. note that if you use expo you need to update to sdk32 because it requires some updates to react-native-gesture-handler

brentvatne avatar Jan 09 '19 20:01 brentvatne

i tried [email protected], the animation is slightly smoother than before, but still not as smooth as react navigation 2. And i found a problem with 3.1.0, in previous versions the drawer open when we make gesture/dragging from the edge of the left/right side of the screen, now i can open the drawer by dragging from the center or the opposite side of the screen, and because in my application there is a carousel in the UI, the swipe function of the carousel stopped working.

rzdev avatar Jan 10 '19 03:01 rzdev

can you try out [email protected] and let me know if this helps? this includes the upstream changes from react-native-gesture-handler to improve performance.

i haven't tagged this release as latest yet but if a few people confirm that it at least improves their situation then i will. note that if you use expo you need to update to sdk32 because it requires some updates to react-native-gesture-handler

I have tried it out using [email protected] on Android 8.0.0 and iOS 12.1.1 on emulators the performance is satisfactory for both android and iOS, on devices for iOS it works smooth but for Android it isn't working fine and seems to show the sluggish behaviour

i1990jain avatar Jan 10 '19 08:01 i1990jain

 "react-native": "0.57.7",
 "react-navigation": "3.1.0"

Tried it out still laggy and if there are continuous swipe to the drawer there is a delay in the app navigation.

jfreak avatar Jan 10 '19 13:01 jfreak

at this point the only further optimization we can do is switch over to using reanimated for the gesture, which we plan to do for v4. we won't switch back from the rngh drawerlayout to using drawerlayoutandroid because there are too many issues with it despite performance being good. you're welcome to fork react-navigation-drawer and switch it to use the drawerlayoutandroid component if you like.

brentvatne avatar Jan 12 '19 18:01 brentvatne

When is the v4 planned?

mithunmo avatar Jan 28 '19 17:01 mithunmo

Is there any update for the relase of v4? Thanks :)

jayzyaj avatar Feb 05 '19 01:02 jayzyaj