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,
|
2019-09-27 05:42:18 +08:00
|
|
|
NativeMethods,
|
2017-10-26 02:07:54 +08:00
|
|
|
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:
|
2019-05-23 15:23:54 +08:00
|
|
|
import {
|
|
|
|
|
TextInputState,
|
|
|
|
|
UIManager,
|
|
|
|
|
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
|
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-12-13 07:47:55 +08:00
|
|
|
import warning from 'shared/warning';
|
2019-02-26 07:00:39 +08:00
|
|
|
|
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(
|
2019-09-27 05:42:18 +08:00
|
|
|
relativeToNativeNode: number | ReactNativeFiberHostComponent,
|
2017-03-21 04:50:31 +08:00
|
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
2019-09-27 05:42:18 +08:00
|
|
|
onFail?: () => void /* currently unused */,
|
2017-03-21 04:50:31 +08:00
|
|
|
) {
|
2019-09-27 05:42:18 +08:00
|
|
|
let relativeNode: ?number;
|
2019-03-30 06:57:06 +08:00
|
|
|
|
|
|
|
|
if (typeof relativeToNativeNode === 'number') {
|
|
|
|
|
// Already a node handle
|
|
|
|
|
relativeNode = relativeToNativeNode;
|
|
|
|
|
} else if (relativeToNativeNode._nativeTag) {
|
|
|
|
|
relativeNode = relativeToNativeNode._nativeTag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (relativeNode == null) {
|
2019-12-07 02:25:54 +08:00
|
|
|
if (__DEV__) {
|
2019-12-13 07:47:55 +08:00
|
|
|
warning(
|
2019-12-07 02:25:54 +08:00
|
|
|
'Warning: ref.measureLayout must be called with a node handle or a ref to a native component.',
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-03-30 06:57:06 +08:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-21 04:50:31 +08:00
|
|
|
UIManager.measureLayout(
|
|
|
|
|
this._nativeTag,
|
2019-03-30 06:57:06 +08:00
|
|
|
relativeNode,
|
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__) {
|
|
|
|
|
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
|
2019-09-27 05:42:18 +08:00
|
|
|
(ReactNativeFiberHostComponent.prototype: NativeMethods);
|
2017-05-25 00:06:30 +08:00
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
export default ReactNativeFiberHostComponent;
|