mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use commands from JS in RefreshControl instead of setNativeProps
Summary: Changelog: [Internal] RefreshControl uses commands instead of setNativeProps Reviewed By: TheSavior Differential Revision: D18475794 fbshipit-source-id: fbfe3fcfa465c821d673bf9a9666c989ba4f9545
This commit is contained in:
committed by
Facebook Github Bot
parent
2237ea6d2e
commit
9c27ccd7d0
@@ -61,4 +61,5 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
|
||||
|
||||
export default (codegenNativeComponent<NativeProps>('PullToRefreshView', {
|
||||
paperComponentName: 'RCTRefreshControl',
|
||||
excludedPlatform: 'android',
|
||||
}): HostComponent<NativeProps>);
|
||||
|
||||
@@ -16,7 +16,10 @@ const React = require('react');
|
||||
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
|
||||
import type {ViewProps} from '../View/ViewPropTypes';
|
||||
import AndroidSwipeRefreshLayoutNativeComponent from './AndroidSwipeRefreshLayoutNativeComponent';
|
||||
import PullToRefreshViewNativeComponent from './PullToRefreshViewNativeComponent';
|
||||
|
||||
import PullToRefreshViewNativeComponent, {
|
||||
Commands as PullToRefreshCommands,
|
||||
} from './PullToRefreshViewNativeComponent';
|
||||
|
||||
let RefreshLayoutConsts: any;
|
||||
if (Platform.OS === 'android') {
|
||||
@@ -138,6 +141,8 @@ class RefreshControl extends React.Component<RefreshControlProps> {
|
||||
_setNativePropsOnRef: ?({refreshing: boolean, ...}) => void;
|
||||
_lastNativeRefreshing = false;
|
||||
|
||||
_nativeRef: ?React.ElementRef<typeof PullToRefreshViewNativeComponent>;
|
||||
|
||||
componentDidMount() {
|
||||
this._lastNativeRefreshing = this.props.refreshing;
|
||||
}
|
||||
@@ -152,16 +157,26 @@ class RefreshControl extends React.Component<RefreshControlProps> {
|
||||
this.props.refreshing !== this._lastNativeRefreshing &&
|
||||
this._setNativePropsOnRef
|
||||
) {
|
||||
this._setNativePropsOnRef({
|
||||
refreshing: this.props.refreshing,
|
||||
});
|
||||
if (Platform.OS === 'android') {
|
||||
this._setNativePropsOnRef({
|
||||
refreshing: this.props.refreshing,
|
||||
});
|
||||
} else if (this._nativeRef) {
|
||||
PullToRefreshCommands.setNativeRefreshing(
|
||||
this._nativeRef,
|
||||
this.props.refreshing,
|
||||
);
|
||||
}
|
||||
this._lastNativeRefreshing = this.props.refreshing;
|
||||
}
|
||||
}
|
||||
|
||||
render(): React.Node {
|
||||
const setRef = ref =>
|
||||
(this._setNativePropsOnRef = ref ? ref.setNativeProps.bind(ref) : null);
|
||||
const setRef = ref => {
|
||||
this._setNativePropsOnRef = ref ? ref.setNativeProps.bind(ref) : null;
|
||||
this._nativeRef = ref;
|
||||
};
|
||||
|
||||
if (Platform.OS === 'ios') {
|
||||
const {
|
||||
enabled,
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated by codegen project: GeneratePropsJavaDelegate.js
|
||||
*/
|
||||
|
||||
package com.facebook.react.viewmanagers;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.BaseViewManagerDelegate;
|
||||
import com.facebook.react.uimanager.BaseViewManagerInterface;
|
||||
import com.facebook.react.uimanager.LayoutShadowNode;
|
||||
|
||||
public class PullToRefreshViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & PullToRefreshViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
|
||||
public PullToRefreshViewManagerDelegate(U viewManager) {
|
||||
super(viewManager);
|
||||
}
|
||||
@Override
|
||||
public void setProperty(T view, String propName, @Nullable Object value) {
|
||||
switch (propName) {
|
||||
case "tintColor":
|
||||
mViewManager.setTintColor(view, value == null ? null : ((Double) value).intValue());
|
||||
break;
|
||||
case "titleColor":
|
||||
mViewManager.setTitleColor(view, value == null ? null : ((Double) value).intValue());
|
||||
break;
|
||||
case "title":
|
||||
mViewManager.setTitle(view, value == null ? null : (String) value);
|
||||
break;
|
||||
case "refreshing":
|
||||
mViewManager.setRefreshing(view, value == null ? false : (boolean) value);
|
||||
break;
|
||||
default:
|
||||
super.setProperty(view, propName, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveCommand(PullToRefreshViewManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case "setNativeRefreshing":
|
||||
viewManager.setNativeRefreshing(view, args.getBoolean(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @generated by codegen project: GeneratePropsJavaInterface.js
|
||||
*/
|
||||
|
||||
package com.facebook.react.viewmanagers;
|
||||
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public interface PullToRefreshViewManagerInterface<T extends View> {
|
||||
void setTintColor(T view, @Nullable Integer value);
|
||||
void setTitleColor(T view, @Nullable Integer value);
|
||||
void setTitle(T view, @Nullable String value);
|
||||
void setRefreshing(T view, boolean value);
|
||||
void setNativeRefreshing(T view, boolean refreshing);
|
||||
}
|
||||
Reference in New Issue
Block a user