Drawer gesture / animation sluggish on Android
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!
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
cc @kmagiera - maybe time for reanimated
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:

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:

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
Experiencing same sluggish animation for createMaterialTopTabNavigator between tabs. Reverting back to v2, animation works fine.
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
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
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 - post a new issue and share a repro and an animation. hid your comment because it's off topic as this is about perf
@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
Confirm. Same problem
"react": "16.6.3",
"react-native": "0.57.8",
"react-native-gesture-handler": "^1.0.12",
"react-navigation": "^3.0.8",
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 Happy New Year! Are you back from holidays?
yeah i might have time for this later in the week
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 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.
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
"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.
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.
When is the v4 planned?
Is there any update for the relase of v4? Thanks :)