2017-03-21 04:50:31 +08:00
|
|
|
/**
|
2018-09-08 06:11:23 +08:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-03-21 04:50:31 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-03-21 04:50:31 +08:00
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
|
2017-10-26 02:07:54 +08:00
|
|
|
import type {
|
|
|
|
|
MeasureInWindowOnSuccessCallback,
|
|
|
|
|
MeasureLayoutOnSuccessCallback,
|
|
|
|
|
MeasureOnSuccessCallback,
|
|
|
|
|
NativeMethodsMixinType,
|
|
|
|
|
ReactNativeBaseComponentViewConfig,
|
|
|
|
|
} from './ReactNativeTypes';
|
2018-05-15 08:12:28 +08:00
|
|
|
import type {Instance} from './ReactNativeHostConfig';
|
2017-10-25 07:55:00 +08:00
|
|
|
|
|
|
|
|
// Modules provided by RN:
|
2017-11-03 03:50:03 +08:00
|
|
|
import TextInputState from 'TextInputState';
|
|
|
|
|
import UIManager from 'UIManager';
|
2017-03-21 04:50:31 +08:00
|
|
|
|
2018-11-20 07:32:54 +08:00
|
|
|
import {create} from './ReactNativeAttributePayload';
|
2018-08-31 01:42:09 +08:00
|
|
|
import {
|
|
|
|
|
mountSafeCallback_NOT_REALLY_SAFE,
|
|
|
|
|
warnForStyleProps,
|
|
|
|
|
} from './NativeMethodsMixinUtils';
|
2017-03-21 04:50:31 +08:00
|
|
|
|
2019-02-26 07:00:39 +08:00
|
|
|
import warningWithoutStack from 'shared/warningWithoutStack';
|
|
|
|
|
import {warnAboutDeprecatedSetNativeProps} from 'shared/ReactFeatureFlags';
|
|
|
|
|
|
2017-03-21 04:50:31 +08:00
|
|
|
/**
|
|
|
|
|
* This component defines the same methods as NativeMethodsMixin but without the
|
|
|
|
|
* findNodeHandle wrapper. This wrapper is unnecessary for HostComponent views
|
|
|
|
|
* and would also result in a circular require.js dependency (since
|
|
|
|
|
* ReactNativeFiber depends on this component and NativeMethodsMixin depends on
|
|
|
|
|
* ReactNativeFiber).
|
|
|
|
|
*/
|
2017-05-25 00:06:30 +08:00
|
|
|
class ReactNativeFiberHostComponent {
|
2017-03-21 04:50:31 +08:00
|
|
|
_children: Array<Instance | number>;
|
|
|
|
|
_nativeTag: number;
|
2018-08-30 04:54:58 +08:00
|
|
|
viewConfig: ReactNativeBaseComponentViewConfig<>;
|
2017-03-21 04:50:31 +08:00
|
|
|
|
2018-08-30 04:54:58 +08:00
|
|
|
constructor(tag: number, viewConfig: ReactNativeBaseComponentViewConfig<>) {
|
2017-03-21 04:50:31 +08:00
|
|
|
this._nativeTag = tag;
|
|
|
|
|
this._children = [];
|
|
|
|
|
this.viewConfig = viewConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blur() {
|
|
|
|
|
TextInputState.blurTextInput(this._nativeTag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
|
TextInputState.focusTextInput(this._nativeTag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measure(callback: MeasureOnSuccessCallback) {
|
2018-08-31 01:42:09 +08:00
|
|
|
UIManager.measure(
|
|
|
|
|
this._nativeTag,
|
|
|
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
|
|
|
|
|
);
|
2017-03-21 04:50:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
|
|
|
|
|
UIManager.measureInWindow(
|
|
|
|
|
this._nativeTag,
|
2018-08-31 01:42:09 +08:00
|
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
|
2017-03-21 04:50:31 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measureLayout(
|
|
|
|
|
relativeToNativeNode: number,
|
|
|
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
|
|
|
onFail: () => void /* currently unused */,
|
|
|
|
|
) {
|
|
|
|
|
UIManager.measureLayout(
|
|
|
|
|
this._nativeTag,
|
|
|
|
|
relativeToNativeNode,
|
2018-08-31 01:42:09 +08:00
|
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
|
|
|
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess),
|
2017-03-21 04:50:31 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setNativeProps(nativeProps: Object) {
|
|
|
|
|
if (__DEV__) {
|
2019-02-26 07:00:39 +08:00
|
|
|
if (warnAboutDeprecatedSetNativeProps) {
|
|
|
|
|
warningWithoutStack(
|
|
|
|
|
false,
|
|
|
|
|
'Warning: Calling ref.setNativeProps(nativeProps) ' +
|
|
|
|
|
'is deprecated and will be removed in a future release. ' +
|
|
|
|
|
'Use the setNativeProps export from the react-native package instead.' +
|
|
|
|
|
"\n\timport {setNativeProps} from 'react-native';\n\tsetNativeProps(ref, nativeProps);\n",
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-03-21 04:50:31 +08:00
|
|
|
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 07:32:54 +08:00
|
|
|
const updatePayload = create(nativeProps, this.viewConfig.validAttributes);
|
2017-03-21 04:50:31 +08:00
|
|
|
|
2017-08-23 04:31:46 +08:00
|
|
|
// Avoid the overhead of bridge calls if there's no update.
|
|
|
|
|
// This is an expensive no-op for Android, and causes an unnecessary
|
|
|
|
|
// view invalidation for certain components (eg RCTTextInput) on iOS.
|
|
|
|
|
if (updatePayload != null) {
|
|
|
|
|
UIManager.updateView(
|
|
|
|
|
this._nativeTag,
|
|
|
|
|
this.viewConfig.uiViewClassName,
|
|
|
|
|
updatePayload,
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-03-21 04:50:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 00:06:30 +08:00
|
|
|
// eslint-disable-next-line no-unused-expressions
|
|
|
|
|
(ReactNativeFiberHostComponent.prototype: NativeMethodsMixinType);
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
export default ReactNativeFiberHostComponent;
|