mirror of
https://github.com/facebook/react.git
synced 2026-02-24 04:33:04 +00:00
Basically make `console.error` and `console.warn` behave like normal - when a component stack isn't appended. I need this because I need to be able to print rich logs with the component stack option and to be able to disable instrumentation completely in `console.createTask` environments that don't need it. Currently we can't print logs with richer objects because they're toString:ed first. In practice, pretty much all arguments we log are already toString:ed so it's not necessary anyway. Some might be like a number. So it would only be a problem if some environment can't handle proper consoles but then it's up to that environment to toString it before logging. The `Warning: ` prefix is historic and is both noisy and confusing. It's mostly unnecessary since the UI surrounding `console.error` and `console.warn` tend to have visual treatment around it anyway. However, it's actively misleading when `console.error` gets prefixed with a Warning that we consider an error level. There's an argument to be made that some of our `console.error` don't make the bar for an error but then the argument is to downgrade each of those to `console.warn` - not to brand all our actual error logging with `Warning: `. Apparently something needs to change in React Native before landing this because it depends on the prefix somehow which probably doesn't make sense already.
131 lines
3.3 KiB
JavaScript
131 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import type {ElementRef} from 'react';
|
|
import type {
|
|
HostComponent,
|
|
MeasureInWindowOnSuccessCallback,
|
|
MeasureLayoutOnSuccessCallback,
|
|
MeasureOnSuccessCallback,
|
|
INativeMethods,
|
|
ViewConfig,
|
|
} from './ReactNativeTypes';
|
|
import type {Instance} from './ReactFiberConfigNative';
|
|
|
|
// Modules provided by RN:
|
|
import {
|
|
TextInputState,
|
|
UIManager,
|
|
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
|
|
|
|
import {create} from './ReactNativeAttributePayload';
|
|
import {
|
|
mountSafeCallback_NOT_REALLY_SAFE,
|
|
warnForStyleProps,
|
|
} from './NativeMethodsMixinUtils';
|
|
|
|
class ReactNativeFiberHostComponent implements INativeMethods {
|
|
_children: Array<Instance | number>;
|
|
_nativeTag: number;
|
|
_internalFiberInstanceHandleDEV: Object;
|
|
viewConfig: ViewConfig;
|
|
|
|
constructor(
|
|
tag: number,
|
|
viewConfig: ViewConfig,
|
|
internalInstanceHandleDEV: Object,
|
|
) {
|
|
this._nativeTag = tag;
|
|
this._children = [];
|
|
this.viewConfig = viewConfig;
|
|
if (__DEV__) {
|
|
this._internalFiberInstanceHandleDEV = internalInstanceHandleDEV;
|
|
}
|
|
}
|
|
|
|
blur() {
|
|
TextInputState.blurTextInput(this);
|
|
}
|
|
|
|
focus() {
|
|
TextInputState.focusTextInput(this);
|
|
}
|
|
|
|
measure(callback: MeasureOnSuccessCallback) {
|
|
UIManager.measure(
|
|
this._nativeTag,
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
|
|
);
|
|
}
|
|
|
|
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
|
|
UIManager.measureInWindow(
|
|
this._nativeTag,
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, callback),
|
|
);
|
|
}
|
|
|
|
measureLayout(
|
|
relativeToNativeNode: number | ElementRef<HostComponent<mixed>>,
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
onFail?: () => void /* currently unused */,
|
|
) {
|
|
let relativeNode: ?number;
|
|
|
|
if (typeof relativeToNativeNode === 'number') {
|
|
// Already a node handle
|
|
relativeNode = relativeToNativeNode;
|
|
} else {
|
|
const nativeNode: ReactNativeFiberHostComponent =
|
|
(relativeToNativeNode: any);
|
|
if (nativeNode._nativeTag) {
|
|
relativeNode = nativeNode._nativeTag;
|
|
}
|
|
}
|
|
|
|
if (relativeNode == null) {
|
|
if (__DEV__) {
|
|
console.error(
|
|
'ref.measureLayout must be called with a node handle or a ref to a native component.',
|
|
);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
UIManager.measureLayout(
|
|
this._nativeTag,
|
|
relativeNode,
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, onFail),
|
|
mountSafeCallback_NOT_REALLY_SAFE(this, onSuccess),
|
|
);
|
|
}
|
|
|
|
setNativeProps(nativeProps: Object) {
|
|
if (__DEV__) {
|
|
warnForStyleProps(nativeProps, this.viewConfig.validAttributes);
|
|
}
|
|
|
|
const updatePayload = create(nativeProps, this.viewConfig.validAttributes);
|
|
|
|
// 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,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default ReactNativeFiberHostComponent;
|