From cfacc0f0ba78ae3577ed4e2c91a3453cce302f1d Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Fri, 24 Feb 2017 12:25:49 -0800 Subject: [PATCH 01/11] Move BackAndroid -> BackHandler, add Apple TV support for back nav --- Libraries/ReactNative/renderApplication.js | 4 +- Libraries/Utilities/BackAndroid.ios.js | 28 ------ ...roid.android.js => BackHandler.android.js} | 12 +-- Libraries/Utilities/BackHandler.ios.js | 92 +++++++++++++++++++ Libraries/react-native/react-native.js | 4 +- 5 files changed, 103 insertions(+), 37 deletions(-) delete mode 100644 Libraries/Utilities/BackAndroid.ios.js rename Libraries/Utilities/{BackAndroid.android.js => BackHandler.android.js} (90%) create mode 100644 Libraries/Utilities/BackHandler.ios.js diff --git a/Libraries/ReactNative/renderApplication.js b/Libraries/ReactNative/renderApplication.js index 26cf1bed7f143a..0175b5c6f58e6e 100644 --- a/Libraries/ReactNative/renderApplication.js +++ b/Libraries/ReactNative/renderApplication.js @@ -18,8 +18,8 @@ var ReactNative = require('ReactNative'); var invariant = require('fbjs/lib/invariant'); -// require BackAndroid so it sets the default handler that exits the app if no listeners respond -require('BackAndroid'); +// require BackHandler so it sets the default handler that exits the app if no listeners respond +require('BackHandler'); function renderApplication( RootComponent: ReactClass, diff --git a/Libraries/Utilities/BackAndroid.ios.js b/Libraries/Utilities/BackAndroid.ios.js deleted file mode 100644 index 3993c918294878..00000000000000 --- a/Libraries/Utilities/BackAndroid.ios.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * iOS stub for BackAndroid.android.js - * - * @providesModule BackAndroid - */ - -'use strict'; - -function emptyFunction() {} - -const BackAndroid = { - exitApp: emptyFunction, - addEventListener() { - return { - remove: emptyFunction, - }; - }, - removeEventListener: emptyFunction, -}; - -module.exports = BackAndroid; diff --git a/Libraries/Utilities/BackAndroid.android.js b/Libraries/Utilities/BackHandler.android.js similarity index 90% rename from Libraries/Utilities/BackAndroid.android.js rename to Libraries/Utilities/BackHandler.android.js index c3295d927b37ef..02f8a632090a51 100644 --- a/Libraries/Utilities/BackAndroid.android.js +++ b/Libraries/Utilities/BackHandler.android.js @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * - * @providesModule BackAndroid + * @providesModule BackHandler */ 'use strict'; @@ -34,7 +34,7 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { } if (invokeDefault) { - BackAndroid.exitApp(); + BackHandler.exitApp(); } }); @@ -47,7 +47,7 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { * Example: * * ```javascript - * BackAndroid.addEventListener('hardwareBackPress', function() { + * BackHandler.addEventListener('hardwareBackPress', function() { * // this.onMainScreen and this.goBack are just examples, you need to use your own implementation here * // Typically you would use the navigator here to go to the last state. * @@ -59,7 +59,7 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { * }); * ``` */ -var BackAndroid = { +var BackHandler = { exitApp: function() { DeviceEventManager.invokeDefaultBackPressHandler(); @@ -71,7 +71,7 @@ var BackAndroid = { ): {remove: () => void} { _backPressSubscriptions.add(handler); return { - remove: () => BackAndroid.removeEventListener(eventName, handler), + remove: () => BackHandler.removeEventListener(eventName, handler), }; }, @@ -84,4 +84,4 @@ var BackAndroid = { }; -module.exports = BackAndroid; +module.exports = BackHandler; diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js new file mode 100644 index 00000000000000..83952bc2a30aca --- /dev/null +++ b/Libraries/Utilities/BackHandler.ios.js @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * On Apple TV, this implements back navigation using the TV remote's menu button. + * On iOS, this just implements a stub. + * + * @providesModule BackHandler + */ + +'use strict'; + +var Platform = require('Platform'); +var TVEventHandler = require('TVEventHandler'); + +type BackPressEventName = $Enum<{ + backPress: string, +}>; + +function emptyFunction() {} + +var BackHandler; + +if (Platform.isTVOS) { + + var _tvEventHandler = new TVEventHandler(); + + var _backPressSubscriptions = new Set(); + + _tvEventHandler.enable(this, function(cmp, evt) { + if (evt && evt.eventType === 'menu') { + var backPressSubscriptions = new Set(_backPressSubscriptions); + var invokeDefault = true; + var subscriptions = [...backPressSubscriptions].reverse(); + for (var i = 0; i < subscriptions.length; ++i) { + if (subscriptions[i]()) { + invokeDefault = false; + break; + } + } + + if (invokeDefault) { + BackHandler.exitApp(); + } + } + }); + + BackHandler = { + exitApp: emptyFunction, + + addEventListener: function ( + eventName: BackPressEventName, + handler: Function + ): {remove: () => void} { + _backPressSubscriptions.add(handler); + return { + remove: () => BackHandler.removeEventListener(eventName, handler), + }; + }, + + removeEventListener: function( + eventName: BackPressEventName, + handler: Function + ): void { + _backPressSubscriptions.delete(handler); + }, + + }; + + +} else { + + + BackHandler = { + exitApp: emptyFunction, + addEventListener() { + return { + remove: emptyFunction, + }; + }, + removeEventListener: emptyFunction, + }; + + +} + +module.exports = BackHandler; + diff --git a/Libraries/react-native/react-native.js b/Libraries/react-native/react-native.js index af7d51298983ce..640cd69950e41b 100644 --- a/Libraries/react-native/react-native.js +++ b/Libraries/react-native/react-native.js @@ -76,7 +76,8 @@ const ReactNative = { get AppRegistry() { return require('AppRegistry'); }, get AppState() { return require('AppState'); }, get AsyncStorage() { return require('AsyncStorage'); }, - get BackAndroid() { return require('BackAndroid'); }, + get BackAndroid() { return require('BackHandler'); }, // Deprecated: leave this until external projects like react-navigation move to BackHandler + get BackHandler() { return require('BackHandler'); }, get CameraRoll() { return require('CameraRoll'); }, get Clipboard() { return require('Clipboard'); }, get DatePickerAndroid() { return require('DatePickerAndroid'); }, @@ -101,6 +102,7 @@ const ReactNative = { get StyleSheet() { return require('StyleSheet'); }, get Systrace() { return require('Systrace'); }, get TimePickerAndroid() { return require('TimePickerAndroid'); }, + get TVEventHandler() { return require('TVEventHandler'); }, get UIManager() { return require('UIManager'); }, get Vibration() { return require('Vibration'); }, get VibrationIOS() { return require('VibrationIOS'); }, From 480c69486e4f05ff3d5d43cc3245f18d50fb72c0 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Mon, 27 Feb 2017 11:35:14 -0800 Subject: [PATCH 02/11] Generate warnings when BackAndroid is used --- Libraries/Utilities/BackAndroid.js | 46 ++++++++++++++++++++++++++ Libraries/react-native/react-native.js | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Libraries/Utilities/BackAndroid.js diff --git a/Libraries/Utilities/BackAndroid.js b/Libraries/Utilities/BackAndroid.js new file mode 100644 index 00000000000000..86415adcb437d1 --- /dev/null +++ b/Libraries/Utilities/BackAndroid.js @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * BackAndroid has been moved to BackHandler. This stub calls BackHandler methods + * after generating a warning to remind users to move to the new BackHandler module. + * + * @providesModule BackAndroid + */ + +'use strict'; + +var BackHandler = require('BackHandler'); + +var warning = require('fbjs/lib/warning'); + +var BackAndroid = { + + exitApp: function() { + warning(false, 'BackAndroid is deprecated. Please use BackHandler instead.'); + BackHandler.exitApp(); + }, + + addEventListener: function ( + eventName: BackPressEventName, + handler: Function + ): {remove: () => void} { + warning(false, 'BackAndroid is deprecated. Please use BackHandler instead.'); + return BackHandler.addEventListener(eventName, handler); + }, + + removeEventListener: function( + eventName: BackPressEventName, + handler: Function + ): void { + warning(false, 'BackAndroid is deprecated. Please use BackHandler instead.'); + BackHandler.removeEventListener(eventName, handler); + }, + +}; + +module.exports = BackAndroid; diff --git a/Libraries/react-native/react-native.js b/Libraries/react-native/react-native.js index 640cd69950e41b..a3f1655b6cb797 100644 --- a/Libraries/react-native/react-native.js +++ b/Libraries/react-native/react-native.js @@ -76,7 +76,7 @@ const ReactNative = { get AppRegistry() { return require('AppRegistry'); }, get AppState() { return require('AppState'); }, get AsyncStorage() { return require('AsyncStorage'); }, - get BackAndroid() { return require('BackHandler'); }, // Deprecated: leave this until external projects like react-navigation move to BackHandler + get BackAndroid() { return require('BackAndroid'); }, // deprecated: use BackHandler instead get BackHandler() { return require('BackHandler'); }, get CameraRoll() { return require('CameraRoll'); }, get Clipboard() { return require('Clipboard'); }, From 529bde3303a198886be89dfdbbfbfdff2985045a Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Mon, 27 Feb 2017 11:37:29 -0800 Subject: [PATCH 03/11] Add BackHandler to docs list --- website/server/docsList.js | 1 + 1 file changed, 1 insertion(+) diff --git a/website/server/docsList.js b/website/server/docsList.js index 3024c8b68c24c2..b788a4dd4318e2 100644 --- a/website/server/docsList.js +++ b/website/server/docsList.js @@ -56,6 +56,7 @@ const apis = [ '../Libraries/AppState/AppState.js', '../Libraries/Storage/AsyncStorage.js', '../Libraries/Utilities/BackAndroid.android.js', + '../Libraries/Utilities/BackHandler.android.js', '../Libraries/CameraRoll/CameraRoll.js', '../Libraries/Components/Clipboard/Clipboard.js', '../Libraries/Components/DatePickerAndroid/DatePickerAndroid.android.js', From f20012fc6256a49ac489e4483637319987fe5198 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Mon, 27 Feb 2017 12:22:42 -0800 Subject: [PATCH 04/11] Doc comments for BackHandler and BackAndroid --- Libraries/Utilities/BackAndroid.js | 3 +++ Libraries/Utilities/BackHandler.android.js | 11 +++++++- Libraries/Utilities/BackHandler.ios.js | 30 ++++++++++++++++++++++ website/server/docsList.js | 3 ++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Libraries/Utilities/BackAndroid.js b/Libraries/Utilities/BackAndroid.js index 86415adcb437d1..0289b34c65d82c 100644 --- a/Libraries/Utilities/BackAndroid.js +++ b/Libraries/Utilities/BackAndroid.js @@ -18,6 +18,9 @@ var BackHandler = require('BackHandler'); var warning = require('fbjs/lib/warning'); +/** + * Deprecated. Use BackHandler instead. + */ var BackAndroid = { exitApp: function() { diff --git a/Libraries/Utilities/BackHandler.android.js b/Libraries/Utilities/BackHandler.android.js index 02f8a632090a51..66ee01456a863d 100644 --- a/Libraries/Utilities/BackHandler.android.js +++ b/Libraries/Utilities/BackHandler.android.js @@ -39,8 +39,17 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { }); /** - * Detect hardware back button presses, and programmatically invoke the default back button + * Detect hardware button presses for back navigation. + * + * Android: Detect hardware back button presses, and programmatically invoke the default back button * functionality to exit the app if there are no listeners or if none of the listeners return true. + * + * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: + * programmatically disable menu button handling + * functionality to exit the app if there are no listeners or if none of the listeners return true.) + * + * iOS: Not applicable. + * * The event subscriptions are called in reverse order (i.e. last registered subscription first), * and if one subscription returns true then subscriptions registered earlier will not be called. * diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js index 83952bc2a30aca..0e5bd7cb08a318 100644 --- a/Libraries/Utilities/BackHandler.ios.js +++ b/Libraries/Utilities/BackHandler.ios.js @@ -23,6 +23,36 @@ type BackPressEventName = $Enum<{ function emptyFunction() {} +/** + * Detect hardware button presses for back navigation. + * + * Android: Detect hardware back button presses, and programmatically invoke the default back button + * functionality to exit the app if there are no listeners or if none of the listeners return true. + * + * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: + * programmatically disable menu button handling + * functionality to exit the app if there are no listeners or if none of the listeners return true.) + * + * iOS: Not applicable. + * + * The event subscriptions are called in reverse order (i.e. last registered subscription first), + * and if one subscription returns true then subscriptions registered earlier will not be called. + * + * Example: + * + * ```javascript + * BackHandler.addEventListener('hardwareBackPress', function() { + * // this.onMainScreen and this.goBack are just examples, you need to use your own implementation here + * // Typically you would use the navigator here to go to the last state. + * + * if (!this.onMainScreen()) { + * this.goBack(); + * return true; + * } + * return false; + * }); + * ``` + */ var BackHandler; if (Platform.isTVOS) { diff --git a/website/server/docsList.js b/website/server/docsList.js index b788a4dd4318e2..302561885724e6 100644 --- a/website/server/docsList.js +++ b/website/server/docsList.js @@ -55,7 +55,8 @@ const apis = [ '../Libraries/ReactNative/AppRegistry.js', '../Libraries/AppState/AppState.js', '../Libraries/Storage/AsyncStorage.js', - '../Libraries/Utilities/BackAndroid.android.js', + '../Libraries/Utilities/BackAndroid.js', + '../Libraries/Utilities/BackHandler.ios.js', '../Libraries/Utilities/BackHandler.android.js', '../Libraries/CameraRoll/CameraRoll.js', '../Libraries/Components/Clipboard/Clipboard.js', From 19ad6afff361d7ba94b7954ee6355ab94489eaa6 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Mon, 27 Feb 2017 15:25:34 -0800 Subject: [PATCH 05/11] Remove trailing spaces --- Libraries/Utilities/BackHandler.android.js | 2 +- Libraries/Utilities/BackHandler.ios.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/Utilities/BackHandler.android.js b/Libraries/Utilities/BackHandler.android.js index 66ee01456a863d..d8ca9b5eb567c9 100644 --- a/Libraries/Utilities/BackHandler.android.js +++ b/Libraries/Utilities/BackHandler.android.js @@ -44,7 +44,7 @@ RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function() { * Android: Detect hardware back button presses, and programmatically invoke the default back button * functionality to exit the app if there are no listeners or if none of the listeners return true. * - * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: + * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: * programmatically disable menu button handling * functionality to exit the app if there are no listeners or if none of the listeners return true.) * diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js index 0e5bd7cb08a318..becc0584301d9c 100644 --- a/Libraries/Utilities/BackHandler.ios.js +++ b/Libraries/Utilities/BackHandler.ios.js @@ -29,7 +29,7 @@ function emptyFunction() {} * Android: Detect hardware back button presses, and programmatically invoke the default back button * functionality to exit the app if there are no listeners or if none of the listeners return true. * - * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: + * tvOS: Detect presses of the menu button on the TV remote. (Still to be implemented: * programmatically disable menu button handling * functionality to exit the app if there are no listeners or if none of the listeners return true.) * From d481d41c07dd640dc4ea202f56da4f442b6a0d06 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Tue, 28 Feb 2017 12:55:36 -0800 Subject: [PATCH 06/11] Remove extra lines, var -> const --- Libraries/Utilities/BackHandler.ios.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Libraries/Utilities/BackHandler.ios.js b/Libraries/Utilities/BackHandler.ios.js index becc0584301d9c..958ec69e5c0558 100644 --- a/Libraries/Utilities/BackHandler.ios.js +++ b/Libraries/Utilities/BackHandler.ios.js @@ -14,8 +14,8 @@ 'use strict'; -var Platform = require('Platform'); -var TVEventHandler = require('TVEventHandler'); +const Platform = require('Platform'); +const TVEventHandler = require('TVEventHandler'); type BackPressEventName = $Enum<{ backPress: string, @@ -53,12 +53,10 @@ function emptyFunction() {} * }); * ``` */ -var BackHandler; +let BackHandler; if (Platform.isTVOS) { - - var _tvEventHandler = new TVEventHandler(); - + const _tvEventHandler = new TVEventHandler(); var _backPressSubscriptions = new Set(); _tvEventHandler.enable(this, function(cmp, evt) { @@ -101,10 +99,8 @@ if (Platform.isTVOS) { }; - } else { - BackHandler = { exitApp: emptyFunction, addEventListener() { @@ -115,8 +111,6 @@ if (Platform.isTVOS) { removeEventListener: emptyFunction, }; - } module.exports = BackHandler; - From 24b0d4de0031491db514f0f78440a725ee72f0b6 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Wed, 1 Mar 2017 12:23:18 -0800 Subject: [PATCH 07/11] Fix warning import in VirtualizedSectionList --- Libraries/CustomComponents/Lists/VirtualizedSectionList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/CustomComponents/Lists/VirtualizedSectionList.js b/Libraries/CustomComponents/Lists/VirtualizedSectionList.js index c0bacd3c8ba4fc..104e1ef87568e1 100644 --- a/Libraries/CustomComponents/Lists/VirtualizedSectionList.js +++ b/Libraries/CustomComponents/Lists/VirtualizedSectionList.js @@ -37,7 +37,7 @@ const View = require('View'); const VirtualizedList = require('VirtualizedList'); const invariant = require('invariant'); -const warning = require('warning'); +const warning = require('fbjs/lib/warning'); import type {ViewToken} from 'ViewabilityHelper'; import type {Props as VirtualizedListProps} from 'VirtualizedList'; From 441e60c55a33e476cc26ab5e88575215bb7e345c Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Fri, 3 Mar 2017 15:55:14 -0800 Subject: [PATCH 08/11] Fix UIExplorer example code to use BackHandler --- Examples/UIExplorer/js/UIExplorerApp.android.js | 4 ++-- Examples/UIExplorer/js/UIExplorerApp.ios.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Examples/UIExplorer/js/UIExplorerApp.android.js b/Examples/UIExplorer/js/UIExplorerApp.android.js index 683f53b1342ab1..1e13a212ceb6bd 100644 --- a/Examples/UIExplorer/js/UIExplorerApp.android.js +++ b/Examples/UIExplorer/js/UIExplorerApp.android.js @@ -25,7 +25,7 @@ const AppRegistry = require('AppRegistry'); const AsyncStorage = require('AsyncStorage'); -const BackAndroid = require('BackAndroid'); +const BackHandler = require('BackHandler'); const Dimensions = require('Dimensions'); const DrawerLayoutAndroid = require('DrawerLayoutAndroid'); const Linking = require('Linking'); @@ -73,7 +73,7 @@ class UIExplorerApp extends React.Component { state: UIExplorerNavigationState; componentWillMount() { - BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress); + BackHandler.addEventListener('hardwareBackPress', this._handleBackButtonPress); } componentDidMount() { diff --git a/Examples/UIExplorer/js/UIExplorerApp.ios.js b/Examples/UIExplorer/js/UIExplorerApp.ios.js index 802413c0468894..f57e4fbf8c35bb 100644 --- a/Examples/UIExplorer/js/UIExplorerApp.ios.js +++ b/Examples/UIExplorer/js/UIExplorerApp.ios.js @@ -24,6 +24,7 @@ 'use strict'; const AsyncStorage = require('AsyncStorage'); +const BackHandler = require('BackHandler'); const Linking = require('Linking'); const React = require('react'); const ReactNative = require('react-native'); @@ -68,6 +69,10 @@ class UIExplorerApp extends React.Component { props: Props; state: UIExplorerNavigationState; + componentWillMount() { + BackHandler.addEventListener('hardwareBackPress', this._handleBack); + } + componentDidMount() { Linking.getInitialURL().then((url) => { AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => { From 2656bdc37692d20b7d6d647294f8c89f5a1e3baf Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Fri, 3 Mar 2017 16:00:05 -0800 Subject: [PATCH 09/11] Fix VirtualizedList for tvOS (FlatList example in UIExplorer is broken for tvOS without this change) --- Libraries/CustomComponents/Lists/VirtualizedList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/CustomComponents/Lists/VirtualizedList.js b/Libraries/CustomComponents/Lists/VirtualizedList.js index 5adb1a6fab5c16..75a5738c234ba4 100644 --- a/Libraries/CustomComponents/Lists/VirtualizedList.js +++ b/Libraries/CustomComponents/Lists/VirtualizedList.js @@ -33,6 +33,7 @@ 'use strict'; const Batchinator = require('Batchinator'); +const Platform = require('Platform'); const React = require('React'); const RefreshControl = require('RefreshControl'); const ScrollView = require('ScrollView'); @@ -251,7 +252,7 @@ class VirtualizedList extends React.PureComponent { onEndReachedThreshold: 2, // multiples of length removeClippedSubviews: true, renderScrollComponent: (props: Props) => { - if (props.onRefresh) { + if (props.onRefresh && !Platform.isTVOS) { invariant( typeof props.refreshing === 'boolean', '`refreshing` prop must be set as a boolean in order to use `onRefresh`, but got `' + From c2406ccb8f6704efbf024d12b5562777cafc1024 Mon Sep 17 00:00:00 2001 From: dlowder-salesforce Date: Sat, 4 Mar 2017 12:53:02 -0800 Subject: [PATCH 10/11] ScrollView shouldn't automatically use RefreshControl on tvOS --- Libraries/Components/ScrollView/ScrollView.js | 4 +++- Libraries/CustomComponents/Lists/VirtualizedList.js | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 54c6029fa303de..9af645272f60ab 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -677,7 +677,9 @@ const ScrollView = React.createClass({ props.decelerationRate = processDecelerationRate(decelerationRate); } - const refreshControl = this.props.refreshControl; + // Native refresh control doesn't exist on tvOS + const refreshControl = Platform.isTVOS ? null : this.props.refreshControl; + if (refreshControl) { if (Platform.OS === 'ios') { // On iOS the RefreshControl is a child of the ScrollView. diff --git a/Libraries/CustomComponents/Lists/VirtualizedList.js b/Libraries/CustomComponents/Lists/VirtualizedList.js index 75a5738c234ba4..5adb1a6fab5c16 100644 --- a/Libraries/CustomComponents/Lists/VirtualizedList.js +++ b/Libraries/CustomComponents/Lists/VirtualizedList.js @@ -33,7 +33,6 @@ 'use strict'; const Batchinator = require('Batchinator'); -const Platform = require('Platform'); const React = require('React'); const RefreshControl = require('RefreshControl'); const ScrollView = require('ScrollView'); @@ -252,7 +251,7 @@ class VirtualizedList extends React.PureComponent { onEndReachedThreshold: 2, // multiples of length removeClippedSubviews: true, renderScrollComponent: (props: Props) => { - if (props.onRefresh && !Platform.isTVOS) { + if (props.onRefresh) { invariant( typeof props.refreshing === 'boolean', '`refreshing` prop must be set as a boolean in order to use `onRefresh`, but got `' + From 883d2552ef80ee1648d80a68957033a501262dc4 Mon Sep 17 00:00:00 2001 From: Douglas Lowder Date: Mon, 6 Mar 2017 15:23:43 -0800 Subject: [PATCH 11/11] Back out RefreshControl change for submission as a separate PR --- Libraries/Components/ScrollView/ScrollView.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index f7e61b0011ba42..fc5c419c714a6b 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -677,8 +677,7 @@ const ScrollView = React.createClass({ props.decelerationRate = processDecelerationRate(decelerationRate); } - // Native refresh control doesn't exist on tvOS - const refreshControl = Platform.isTVOS ? null : this.props.refreshControl; + const refreshControl = this.props.refreshControl; if (refreshControl) { if (Platform.OS === 'ios') {