From 4f15c84d3e0272f8f7ff8a97212c39576616a1a0 Mon Sep 17 00:00:00 2001 From: Krzysztof Borowy Date: Thu, 14 Mar 2019 13:13:46 +0100 Subject: [PATCH 1/3] feat: adds clipping control via prop --- README.md | 9 +++++++++ src/Pager.js | 19 ++++++++++++------- src/TabView.js | 4 ++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 21ee2cdc..b49d8c65 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,15 @@ This view is usually only shown for a split second. Keep it lightweight. By default, this renders `null`. + +##### `removeClippedSubviews` + +*Note*: Don't enable this on iOS where this is buggy and views don't re-appear. + +Removes not visible subviews to improve memory usage. + +`false` by default. + ##### `keyboardDismissMode` String indicating whether the keyboard gets dismissed in response to a drag gesture. Possible values are: diff --git a/src/Pager.js b/src/Pager.js index da032681..f3a42e51 100644 --- a/src/Pager.js +++ b/src/Pager.js @@ -1,7 +1,7 @@ /* @flow */ import * as React from 'react'; -import { StyleSheet, Platform, Keyboard } from 'react-native'; +import { StyleSheet, Keyboard } from 'react-native'; import { PanGestureHandler, State } from 'react-native-gesture-handler'; import Animated, { Easing } from 'react-native-reanimated'; @@ -72,6 +72,9 @@ type Props = {| onIndexChange: (index: number) => mixed, navigationState: NavigationState, layout: Layout, + // Clip unfocused views to improve memory usage + // Don't enable this on iOS where this is buggy and views don't re-appear + removeClippedSubviews?: boolean, children: (props: {| // Animated value which represents the state of current index // It can include fractional digits as it represents the intermediate value @@ -444,7 +447,13 @@ export default class Pager extends React.Component> { ]); render() { - const { layout, navigationState, swipeEnabled, children } = this.props; + const { + layout, + navigationState, + swipeEnabled, + children, + removeClippedSubviews, + } = this.props; // Make sure that the translation doesn't exceed the bounds to prevent overscrolling const translateX = min( @@ -479,11 +488,7 @@ export default class Pager extends React.Component> { failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]} > = {| tabBarPosition: 'top' | 'bottom', initialLayout?: { width?: number, height?: number }, lazy: boolean, + removeClippedSubviews?: boolean, sceneContainerStyle?: ViewStyleProp, style?: ViewStyleProp, |}; @@ -51,6 +52,7 @@ export default class TabView extends React.Component< keyboardDismissMode: 'on-drag', swipeEnabled: true, lazy: false, + removeClippedSubviews: false, }; state = { @@ -87,6 +89,7 @@ export default class TabView extends React.Component< onSwipeEnd, navigationState, lazy, + removeClippedSubviews, keyboardDismissMode, swipeEnabled, swipeDistanceThreshold, @@ -112,6 +115,7 @@ export default class TabView extends React.Component< onSwipeStart={onSwipeStart} onSwipeEnd={onSwipeEnd} onIndexChange={this._jumpToIndex} + removeClippedSubviews={removeClippedSubviews} > {({ position, render, addListener, removeListener, jumpTo }) => { // All of the props here must not change between re-renders From ee171c390639080e9a17536f7d42be3b6a552a0d Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 14 Mar 2019 13:18:13 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b49d8c65..11e82c9c 100644 --- a/README.md +++ b/README.md @@ -252,11 +252,9 @@ By default, this renders `null`. ##### `removeClippedSubviews` -*Note*: Don't enable this on iOS where this is buggy and views don't re-appear. +Removes not visible subviews to improve memory usage. Defaults to `false`. -Removes not visible subviews to improve memory usage. - -`false` by default. +**Note**: Don't enable this on iOS where this is buggy and views don't re-appear. ##### `keyboardDismissMode` From 528eb9a0f197669adc79fe214f005b275fafeffa Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 14 Mar 2019 13:20:25 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11e82c9c..b651b142 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ By default, this renders `null`. ##### `removeClippedSubviews` -Removes not visible subviews to improve memory usage. Defaults to `false`. +Boolean indicating whether to remove invisible views (such as unfocused screens) from the native view hierarchy to improve memory usage. Defaults to `false`. **Note**: Don't enable this on iOS where this is buggy and views don't re-appear.