From 2a4882e7e9f5a12cf251bafb8f9eebb36f0ba7db Mon Sep 17 00:00:00 2001 From: Eli White Date: Thu, 20 Jun 2019 13:58:15 -0700 Subject: [PATCH] Using generated ViewConfigs for AndroidSwipeRefreshLayoutNativeComponent Summary: $title Reviewed By: rickhanlonii Differential Revision: D15914074 fbshipit-source-id: 40fa6dcdf27b4fb88d936c439ba66a11e55966a9 --- ...ndroidSwipeRefreshLayoutNativeComponent.js | 46 ++++++++++--------- .../RefreshControl/RefreshControl.js | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js b/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js index 487dcf9ae56..0dc7b3121e9 100644 --- a/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js +++ b/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js @@ -10,18 +10,16 @@ 'use strict'; -const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import codegenNativeComponent from '../../Utilities/codegenNativeComponent'; +import type { + DirectEvent, + Float, + Int32, + WithDefault, +} from '../../Types/CodegenTypes'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; import type {ViewProps} from '../View/ViewPropTypes'; -import type {NativeComponent} from '../../Renderer/shims/ReactNative'; - -const AndroidSwipeRefreshLayout = require('../../ReactNative/UIManager').getViewManagerConfig( - 'AndroidSwipeRefreshLayout', -); -const RefreshLayoutConsts = AndroidSwipeRefreshLayout - ? AndroidSwipeRefreshLayout.Constants - : {SIZE: {}}; type NativeProps = $ReadOnly<{| ...ViewProps, @@ -29,7 +27,7 @@ type NativeProps = $ReadOnly<{| /** * Whether the pull to refresh functionality is enabled. */ - enabled?: ?boolean, + enabled?: ?WithDefault, /** * The colors (at least one) that will be used to draw the refresh indicator. */ @@ -40,29 +38,35 @@ type NativeProps = $ReadOnly<{| progressBackgroundColor?: ?ColorValue, /** * Size of the refresh indicator, see RefreshControl.SIZE. + * + * This type isn't currently accurate. It really is specific numbers + * hard coded in the Android platform. + * + * Also, 1 isn't actually a safe default. We are able to set this here + * because native code isn't currently consuming the generated artifact. + * This will end up being + * size?: ?WithDefault<'default' | 'large', 'default'>, */ - size?: ?( - | typeof RefreshLayoutConsts.SIZE.DEFAULT - | typeof RefreshLayoutConsts.SIZE.LARGE - ), + size?: ?WithDefault, /** * Progress view top offset */ - progressViewOffset?: ?number, + progressViewOffset?: ?WithDefault, /** * Called when the view starts refreshing. */ - onRefresh?: ?() => mixed, + onRefresh?: ?(event: DirectEvent) => mixed, /** * Whether the view should be indicating an active refresh. */ - refreshing: boolean, + refreshing: WithDefault, |}>; -type AndroidSwipeRefreshLayoutNativeType = Class>; - -module.exports = ((requireNativeComponent( +export default codegenNativeComponent( 'AndroidSwipeRefreshLayout', -): any): AndroidSwipeRefreshLayoutNativeType); + { + interfaceOnly: true, + }, +); diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index f6ed8d9e71c..db6844d0947 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -13,7 +13,7 @@ const Platform = require('../../Utilities/Platform'); const React = require('react'); -const AndroidSwipeRefreshLayoutNativeComponent = require('./AndroidSwipeRefreshLayoutNativeComponent'); +import AndroidSwipeRefreshLayoutNativeComponent from './AndroidSwipeRefreshLayoutNativeComponent'; const PullToRefreshViewNativeComponent = require('./PullToRefreshViewNativeComponent'); const nullthrows = require('nullthrows');