Skip to content

Commit

Permalink
Use react-native-screens when available (facebook#54)
Browse files Browse the repository at this point in the history
This change adds support for react-native-screens. Screens package makes it possible to use native primitives to render tabs container and its scenes such that they get properly mounted/unmounted when not visible.

The support has only been added to `createBottomTabNavigator` as the material one renders its own container that's a part of a different package (react-native-tab-view).
  • Loading branch information
kmagiera authored and satya164 committed Aug 18, 2019
1 parent 20e30f5 commit 835e988
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { ScreenContainer } from 'react-native-screens';
import { polyfill } from 'react-lifecycles-compat';
import createTabNavigator, {
type InjectedProps,
Expand Down Expand Up @@ -94,7 +95,7 @@ class TabNavigationView extends React.PureComponent<Props, State> {

return (
<View style={styles.container}>
<View style={styles.pages}>
<ScreenContainer style={styles.pages}>
{routes.map((route, index) => {
if (lazy && !loaded.includes(index)) {
// Don't render a screen if we've never navigated to it
Expand All @@ -116,7 +117,7 @@ class TabNavigationView extends React.PureComponent<Props, State> {
</ResourceSavingScene>
);
})}
</View>
</ScreenContainer>
{this._renderTabBar()}
</View>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/bottom-tabs/src/views/ResourceSavingScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as React from 'react';
import { Platform, StyleSheet, View } from 'react-native';
import { Screen, screensEnabled } from 'react-native-screens';

type Props = {
isVisible: boolean,
Expand All @@ -13,6 +14,10 @@ const FAR_FAR_AWAY = 3000; // this should be big enough to move the whole view o

export default class ResourceSavingScene extends React.Component<Props> {
render() {
if (screensEnabled()) {
const { isVisible, ...rest } = this.props;
return <Screen active={isVisible ? 1 : 0} {...rest} />;
}
const { isVisible, children, style, ...rest } = this.props;

return (
Expand Down

0 comments on commit 835e988

Please sign in to comment.