Skip to content

[pull] master from facebook:master #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Libraries/Components/TextInput/AndroidTextInputNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import requireNativeComponent from '../../ReactNative/requireNativeComponent';
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import type {TextInputNativeCommands} from './TextInputNativeCommands';
import AndroidTextInputViewConfig from './AndroidTextInputViewConfig';
const ReactNativeViewConfigRegistry = require('../../Renderer/shims/ReactNativeViewConfigRegistry');
import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentRegistry';

export type KeyboardType =
// Cross Platform
Expand Down Expand Up @@ -545,17 +545,10 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['focus', 'blur', 'setTextAndSelection'],
});

let AndroidTextInputNativeComponent;
if (global.RN$Bridgeless) {
ReactNativeViewConfigRegistry.register('AndroidTextInput', () => {
return AndroidTextInputViewConfig;
});
AndroidTextInputNativeComponent = 'AndroidTextInput';
} else {
AndroidTextInputNativeComponent = requireNativeComponent<NativeProps>(
'AndroidTextInput',
);
}
let AndroidTextInputNativeComponent = NativeComponentRegistry.get<NativeProps>(
'AndroidTextInput',
() => AndroidTextInputViewConfig,
);

// flowlint-next-line unclear-type:off
export default ((AndroidTextInputNativeComponent: any): HostComponent<NativeProps>);
9 changes: 6 additions & 3 deletions Libraries/Components/TextInput/AndroidTextInputViewConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

import ReactNativeViewViewConfig from '../../Components/View/ReactNativeViewViewConfig';
import {type ViewConfig} from '../../Renderer/shims/ReactNativeTypes';
import {type PartialViewConfig} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';

const AndroidTextInputViewConfig = {
uiViewClassName: 'AndroidTextInput',
Expand Down Expand Up @@ -58,6 +58,9 @@ const AndroidTextInputViewConfig = {
...ReactNativeViewViewConfig.validAttributes,

maxFontSizeMultiplier: true,
adjustsFontSizeToFit: true,
minimumFontScale: true,
autoFocus: true,
placeholder: true,
inlineImagePadding: true,
contextMenuHidden: true,
Expand All @@ -80,7 +83,7 @@ const AndroidTextInputViewConfig = {
returnKeyType: true,
keyboardType: true,
multiline: true,
color: true,
color: {process: require('../../StyleSheet/processColor')},
autoCompleteType: true,
numberOfLines: true,
letterSpacing: true,
Expand Down Expand Up @@ -111,4 +114,4 @@ const AndroidTextInputViewConfig = {
},
};

module.exports = (AndroidTextInputViewConfig: ViewConfig);
module.exports = (AndroidTextInputViewConfig: PartialViewConfig);
3 changes: 3 additions & 0 deletions Libraries/ReactNative/DummyUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = {
}
return null;
},
hasViewManagerConfig: (viewManagerName: string): boolean => {
return viewManagerName === 'RCTVirtualText';
},
getConstants: (): {...} => ({}),
getConstantsForViewManager: (viewManagerName: string) => {},
getDefaultEventTypes: (): Array<$FlowFixMe> => [],
Expand Down
3 changes: 3 additions & 0 deletions Libraries/ReactNative/PaperUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const UIManagerJS = {
getViewManagerConfig(viewManagerName: string): any {
return getViewManagerConfig(viewManagerName);
},
hasViewManagerConfig(viewManagerName: string): boolean {
return getViewManagerConfig(viewManagerName) != null;
},
};

// TODO (T45220498): Remove this.
Expand Down
6 changes: 5 additions & 1 deletion Libraries/ReactNative/UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

'use strict';

import UIManagerInjection from './UIManagerInjection';
import type {Spec} from './NativeUIManager';

interface UIManagerJSInterface extends Spec {
+getViewManagerConfig: (viewManagerName: string) => Object;
+hasViewManagerConfig: (viewManagerName: string) => boolean;
+createView: (
reactTag: ?number,
viewName: string,
Expand All @@ -34,6 +36,8 @@ interface UIManagerJSInterface extends Spec {
const UIManager: UIManagerJSInterface =
global.RN$Bridgeless === true
? require('./DummyUIManager') // No UIManager in bridgeless mode
: require('./PaperUIManager');
: UIManagerInjection.unstable_UIManager == null
? require('./PaperUIManager')
: UIManagerInjection.unstable_UIManager;

module.exports = UIManager;
15 changes: 15 additions & 0 deletions Libraries/ReactNative/UIManagerInjection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 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.
*
* @flow
* @format
*/

'use strict';

export default {
unstable_UIManager: (null: ?any),
};
1 change: 1 addition & 0 deletions Libraries/ReactNative/UIManagerProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = [
'AccessibilityEventTypes',
'UIView',
'getViewManagerConfig',
'hasViewManagerConfig',
'blur',
'focus',
'genericBubblingEventTypes',
Expand Down
3 changes: 1 addition & 2 deletions Libraries/Text/TextNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export const NativeText: HostComponent<NativeTextProps> = (createReactNativeComp
): any);

export const NativeVirtualText: HostComponent<NativeTextProps> =
!global.RN$Bridgeless &&
UIManager.getViewManagerConfig('RCTVirtualText') == null
!global.RN$Bridgeless && !UIManager.hasViewManagerConfig('RCTVirtualText')
? NativeText
: (createReactNativeComponentClass('RCTVirtualText', () => ({
// $FlowFixMe[incompatible-call]
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Utilities/deprecatedPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const UIManager = require('../ReactNative/UIManager');
import UIManager from '../ReactNative/UIManager';

/**
* Adds a deprecation warning when the prop is used.
Expand All @@ -23,7 +23,7 @@ function deprecatedPropType(
// Don't warn for native components.
if (
!global.RN$Bridgeless &&
!UIManager.getViewManagerConfig(componentName) &&
UIManager.hasViewManagerConfig(componentName) &&
props[propName] !== undefined
) {
console.warn(
Expand Down
6 changes: 4 additions & 2 deletions React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ - (void)startSurfaceWithSurfaceId:(SurfaceId)surfaceId
SystraceSection s("-[RCTScheduler startSurfaceWithSurfaceId:...]");

auto props = convertIdToFollyDynamic(initialProps);
_scheduler->startSurface(
surfaceId, RCTStringFromNSString(moduleName), props, layoutConstraints, layoutContext, _animationDriver);
_scheduler->startSurface(surfaceId, RCTStringFromNSString(moduleName), props, layoutConstraints, layoutContext);

_scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate(_animationDriver);

_scheduler->renderTemplateToSurface(
surfaceId, props.getDefault("navigationConfig").getDefault("initialUITemplate", "").getString());
}
Expand Down
10 changes: 10 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ private void attachToReactInstanceManager() {
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachToReactInstanceManager");
ReactMarker.logMarker(ReactMarkerConstants.ROOT_VIEW_ATTACH_TO_REACT_INSTANCE_MANAGER_START);

// React Native requires that the RootView id be managed entirely by React Native, and will
// crash in addRootView/startSurface if the native View id isn't set to NO_ID.
if (getId() != View.NO_ID) {
throw new IllegalViewOperationException(
"Trying to attach a ReactRootView with an explicit id already set to ["
+ getId()
+ "]. React Native uses the id field to track react tags and will overwrite this"
+ " field. If that is fine, explicitly overwrite the id field to View.NO_ID.");
}

try {
if (mIsAttachedToInstance) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ void Binding::startSurface(
moduleName->toStdString(),
initialProps->consume(),
{},
context,
context);

scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate(
animationDriver_);
}

Expand Down Expand Up @@ -306,7 +308,9 @@ void Binding::startSurfaceWithConstraints(
moduleName->toStdString(),
initialProps->consume(),
constraints,
context,
context);

scheduler->findMountingCoordinator(surfaceId)->setMountingOverrideDelegate(
animationDriver_);
}

Expand Down
11 changes: 7 additions & 4 deletions ReactCommon/react/renderer/mounting/MountingCoordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
namespace facebook {
namespace react {

MountingCoordinator::MountingCoordinator(
ShadowTreeRevision baseRevision,
std::weak_ptr<MountingOverrideDelegate const> delegate)
MountingCoordinator::MountingCoordinator(ShadowTreeRevision baseRevision)
: surfaceId_(baseRevision.rootShadowNode->getSurfaceId()),
baseRevision_(baseRevision),
mountingOverrideDelegate_(delegate),
telemetryController_(*this) {
#ifdef RN_SHADOW_TREE_INTROSPECTION
stubViewTree_ = buildStubViewTreeWithoutUsingDifferentiator(
Expand Down Expand Up @@ -181,5 +178,11 @@ TelemetryController const &MountingCoordinator::getTelemetryController() const {
return telemetryController_;
}

void MountingCoordinator::setMountingOverrideDelegate(
std::weak_ptr<MountingOverrideDelegate const> delegate) const {
std::lock_guard<std::mutex> lock(mutex_);
mountingOverrideDelegate_ = delegate;
}

} // namespace react
} // namespace facebook
10 changes: 6 additions & 4 deletions ReactCommon/react/renderer/mounting/MountingCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class MountingCoordinator final {
* The constructor is meant to be used only inside `ShadowTree`, and it's
* `public` only to enable using with `std::make_shared<>`.
*/
MountingCoordinator(
ShadowTreeRevision baseRevision,
std::weak_ptr<MountingOverrideDelegate const> delegate);
MountingCoordinator(ShadowTreeRevision baseRevision);

/*
* Returns the id of the surface that the coordinator belongs to.
Expand Down Expand Up @@ -84,6 +82,9 @@ class MountingCoordinator final {
void updateBaseRevision(ShadowTreeRevision const &baseRevision) const;
void resetLatestRevision() const;

void setMountingOverrideDelegate(
std::weak_ptr<MountingOverrideDelegate const> delegate) const;

/*
* Methods from this section are meant to be used by `ShadowTree` only.
*/
Expand All @@ -109,7 +110,8 @@ class MountingCoordinator final {
mutable better::optional<ShadowTreeRevision> lastRevision_{};
mutable MountingTransaction::Number number_{0};
mutable std::condition_variable signal_;
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate_;
mutable std::weak_ptr<MountingOverrideDelegate const>
mountingOverrideDelegate_;

TelemetryController telemetryController_;

Expand Down
7 changes: 3 additions & 4 deletions ReactCommon/react/renderer/mounting/ShadowTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ ShadowTree::ShadowTree(
SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext,
ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate)
ShadowTreeDelegate const &delegate)
: surfaceId_(surfaceId), delegate_(delegate) {
const auto noopEventEmitter = std::make_shared<const ViewEventEmitter>(
nullptr, -1, std::shared_ptr<const EventDispatcher>());
Expand All @@ -250,8 +249,8 @@ ShadowTree::ShadowTree(
currentRevision_ = ShadowTreeRevision{
rootShadowNode, ShadowTreeRevision::Number{0}, TransactionTelemetry{}};

mountingCoordinator_ = std::make_shared<MountingCoordinator const>(
currentRevision_, mountingOverrideDelegate);
mountingCoordinator_ =
std::make_shared<MountingCoordinator const>(currentRevision_);
}

ShadowTree::~ShadowTree() {
Expand Down
3 changes: 1 addition & 2 deletions ReactCommon/react/renderer/mounting/ShadowTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class ShadowTree final {
SurfaceId surfaceId,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext,
ShadowTreeDelegate const &delegate,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate);
ShadowTreeDelegate const &delegate);

~ShadowTree();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ TEST(StateReconciliationTest, testStateReconciliation) {
auto state1 = shadowNodeAB->getState();
auto shadowTreeDelegate = DummyShadowTreeDelegate{};
ShadowTree shadowTree{
SurfaceId{11},
LayoutConstraints{},
LayoutContext{},
shadowTreeDelegate,
{}};
SurfaceId{11}, LayoutConstraints{}, LayoutContext{}, shadowTreeDelegate};

shadowTree.commit(
[&](RootShadowNode const &oldRootShadowNode) {
Expand Down
41 changes: 22 additions & 19 deletions ReactCommon/react/renderer/scheduler/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ Scheduler::Scheduler(
const EventTarget *eventTarget,
const std::string &type,
const ValueFactory &payloadFactory) {
uiManager->visitBinding([&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.dispatchEvent(
runtime, eventTarget, type, payloadFactory);
});
uiManager->visitBinding(
[&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.dispatchEvent(
runtime, eventTarget, type, payloadFactory);
},
runtime);
};

auto statePipe = [uiManager](StateUpdate const &stateUpdate) {
Expand Down Expand Up @@ -114,6 +116,9 @@ Scheduler::Scheduler(
removeOutstandingSurfacesOnDestruction_ = reactNativeConfig_->getBool(
"react_fabric:remove_outstanding_surfaces_on_destruction_ios");
#endif

uiManager->extractUIManagerBindingOnDemand_ = reactNativeConfig_->getBool(
"react_fabric:extract_uimanagerbinding_on_demand");
}

Scheduler::~Scheduler() {
Expand Down Expand Up @@ -176,27 +181,23 @@ void Scheduler::startSurface(
const std::string &moduleName,
const folly::dynamic &initialProps,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext,
std::weak_ptr<MountingOverrideDelegate const> mountingOverrideDelegate)
const {
const LayoutContext &layoutContext) const {
SystraceSection s("Scheduler::startSurface");

auto shadowTree = std::make_unique<ShadowTree>(
surfaceId,
layoutConstraints,
layoutContext,
*uiManager_,
mountingOverrideDelegate);
surfaceId, layoutConstraints, layoutContext, *uiManager_);

auto uiManager = uiManager_;

uiManager->getShadowTreeRegistry().add(std::move(shadowTree));

runtimeExecutor_([=](jsi::Runtime &runtime) {
uiManager->visitBinding([&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.startSurface(
runtime, surfaceId, moduleName, initialProps);
});
uiManager->visitBinding(
[&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.startSurface(
runtime, surfaceId, moduleName, initialProps);
},
runtime);
});
}

Expand Down Expand Up @@ -260,9 +261,11 @@ void Scheduler::stopSurface(SurfaceId surfaceId) const {
// fail silently.
auto uiManager = uiManager_;
runtimeExecutor_([=](jsi::Runtime &runtime) {
uiManager->visitBinding([&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.stopSurface(runtime, surfaceId);
});
uiManager->visitBinding(
[&](UIManagerBinding const &uiManagerBinding) {
uiManagerBinding.stopSurface(runtime, surfaceId);
},
runtime);
});
}

Expand Down
Loading