diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h index c30a4e2879b1cb..1b00609959e359 100644 --- a/ReactCommon/fabric/attributedstring/conversions.h +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -7,16 +7,16 @@ #pragma once -#include -#include #include #include #include -#include +#include +#include #include #include -#include +#include #include +#include #include namespace facebook { @@ -388,7 +388,8 @@ inline folly::dynamic toDynamic( inline folly::dynamic toDynamic(const TextAttributes &textAttributes) { auto _textAttributes = folly::dynamic::object(); if (textAttributes.foregroundColor) { - _textAttributes("foregroundColor", toDynamic(textAttributes.foregroundColor)); + _textAttributes( + "foregroundColor", toDynamic(textAttributes.foregroundColor)); } if (textAttributes.backgroundColor) { _textAttributes( diff --git a/ReactCommon/fabric/components/view/ViewShadowNode.cpp b/ReactCommon/fabric/components/view/ViewShadowNode.cpp index 1ef7a291b7d29f..edc68a74561050 100644 --- a/ReactCommon/fabric/components/view/ViewShadowNode.cpp +++ b/ReactCommon/fabric/components/view/ViewShadowNode.cpp @@ -15,8 +15,7 @@ const char ViewComponentName[] = "View"; bool ViewShadowNode::isLayoutOnly() const { const auto &viewProps = *std::static_pointer_cast(props_); - return - viewProps.collapsable && + return viewProps.collapsable && // Event listeners !viewProps.onLayout && // Generic Props diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/NSTextStorage+FontScaling.m b/ReactCommon/fabric/textlayoutmanager/platform/ios/NSTextStorage+FontScaling.m index 01f6c8a1a76bcf..36938fa15e1198 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/NSTextStorage+FontScaling.m +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/NSTextStorage+FontScaling.m @@ -8,8 +8,8 @@ #import "NSTextStorage+FontScaling.h" typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) { - RCTTextSizeComparisonSmaller = 1 << 0, - RCTTextSizeComparisonLarger = 1 << 1, + RCTTextSizeComparisonSmaller = 1 << 0, + RCTTextSizeComparisonLarger = 1 << 1, RCTTextSizeComparisonWithinRange = 1 << 2, }; @@ -17,9 +17,8 @@ @implementation NSTextStorage (FontScaling) - (void)scaleFontSizeToFitSize:(CGSize)size minimumFontSize:(CGFloat)minimumFontSize - maximumFontSize:(CGFloat)maximumFontSize -{ - CGFloat bottomRatio = 1.0/128.0; + maximumFontSize:(CGFloat)maximumFontSize { + CGFloat bottomRatio = 1.0 / 128.0; CGFloat topRatio = 128.0; CGFloat ratio = 1.0; @@ -32,13 +31,11 @@ - (void)scaleFontSizeToFitSize:(CGSize)size minimumFontSize:minimumFontSize maximumFontSize:maximumFontSize]; - RCTTextSizeComparisonOptions comparsion = - [self compareToSize:size thresholdRatio:0.01]; + RCTTextSizeComparisonOptions comparsion = [self compareToSize:size + thresholdRatio:0.01]; - if ( - (comparsion & RCTTextSizeComparisonWithinRange) && - (comparsion & RCTTextSizeComparisonSmaller) - ) { + if ((comparsion & RCTTextSizeComparisonWithinRange) && + (comparsion & RCTTextSizeComparisonSmaller)) { return; } else if (comparsion & RCTTextSizeComparisonSmaller) { bottomRatio = ratio; @@ -50,11 +47,9 @@ - (void)scaleFontSizeToFitSize:(CGSize)size ratio = (topRatio + bottomRatio) / 2.0; CGFloat kRatioThreshold = 0.005; - if ( - ABS(topRatio - bottomRatio) < kRatioThreshold || + if (ABS(topRatio - bottomRatio) < kRatioThreshold || ABS(topRatio - ratio) < kRatioThreshold || - ABS(bottomRatio - ratio) < kRatioThreshold - ) { + ABS(bottomRatio - ratio) < kRatioThreshold) { [self replaceCharactersInRange:(NSRange){0, self.length} withAttributedString:originalAttributedString]; @@ -69,9 +64,8 @@ - (void)scaleFontSizeToFitSize:(CGSize)size } } - -- (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size thresholdRatio:(CGFloat)thresholdRatio -{ +- (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size + thresholdRatio:(CGFloat)thresholdRatio { NSLayoutManager *layoutManager = self.layoutManagers.firstObject; NSTextContainer *textContainer = layoutManager.textContainers.firstObject; @@ -79,27 +73,29 @@ - (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size thresholdRatio:(CGFlo // Does it fit the text container? NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; - NSRange truncatedGlyphRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:glyphRange.length - 1]; + NSRange truncatedGlyphRange = [layoutManager + truncatedGlyphRangeInLineFragmentForGlyphAtIndex:glyphRange.length - 1]; if (truncatedGlyphRange.location != NSNotFound) { return RCTTextSizeComparisonLarger; } - CGSize measuredSize = [layoutManager usedRectForTextContainer:textContainer].size; + CGSize measuredSize = + [layoutManager usedRectForTextContainer:textContainer].size; // Does it fit the size? BOOL fitsSize = - size.width >= measuredSize.width && - size.height >= measuredSize.height; + size.width >= measuredSize.width && size.height >= measuredSize.height; CGSize thresholdSize = (CGSize){ - size.width * thresholdRatio, - size.height * thresholdRatio, + size.width * thresholdRatio, + size.height * thresholdRatio, }; RCTTextSizeComparisonOptions result = 0; - result |= (fitsSize) ? RCTTextSizeComparisonSmaller : RCTTextSizeComparisonLarger; + result |= + (fitsSize) ? RCTTextSizeComparisonSmaller : RCTTextSizeComparisonLarger; if (ABS(measuredSize.width - size.width) < thresholdSize.width) { result = result | RCTTextSizeComparisonWithinRange; @@ -110,26 +106,28 @@ - (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size thresholdRatio:(CGFlo - (void)scaleFontSizeWithRatio:(CGFloat)ratio minimumFontSize:(CGFloat)minimumFontSize - maximumFontSize:(CGFloat)maximumFontSize -{ + maximumFontSize:(CGFloat)maximumFontSize { [self beginEditing]; - [self enumerateAttribute:NSFontAttributeName - inRange:(NSRange){0, self.length} - options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired - usingBlock: - ^(UIFont *_Nullable font, NSRange range, BOOL *_Nonnull stop) { - if (!font) { - return; - } - - CGFloat fontSize = MAX(MIN(font.pointSize * ratio, maximumFontSize), minimumFontSize); - - [self addAttribute:NSFontAttributeName - value:[font fontWithSize:fontSize] - range:range]; - } - ]; + [self + enumerateAttribute:NSFontAttributeName + inRange:(NSRange){0, self.length} + options: + NSAttributedStringEnumerationLongestEffectiveRangeNotRequired + usingBlock:^( + UIFont *_Nullable font, NSRange range, BOOL *_Nonnull stop) { + if (!font) { + return; + } + + CGFloat fontSize = + MAX(MIN(font.pointSize * ratio, maximumFontSize), + minimumFontSize); + + [self addAttribute:NSFontAttributeName + value:[font fontWithSize:fontSize] + range:range]; + }]; [self endEditing]; } diff --git a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTFontUtils.mm b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTFontUtils.mm index 3167a5d1268600..dfe13ff861ee31 100644 --- a/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTFontUtils.mm +++ b/ReactCommon/fabric/textlayoutmanager/platform/ios/RCTFontUtils.mm @@ -120,8 +120,8 @@ static UIFontWeight RCTUIFontWeightFromFloat(CGFloat fontWeight) { fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits]; - font = - [UIFont fontWithDescriptor:fontDescriptor size:fontProperties.size]; + font = [UIFont fontWithDescriptor:fontDescriptor + size:fontProperties.size]; } { diff --git a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp index 967397367fb268..f08bb59aabe862 100644 --- a/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp +++ b/ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp @@ -81,7 +81,8 @@ static const std::string componentNameByReactViewName(std::string viewName) { } static const RawProps rawPropsFromDynamic(const folly::dynamic object) { - // TODO: Convert this to something smarter, probably returning `std::iterator`. + // TODO: Convert this to something smarter, probably returning + // `std::iterator`. RawProps result; if (object.isNull()) { @@ -103,13 +104,12 @@ SharedShadowNode ComponentDescriptorRegistry::createNode(Tag tag, const std::str const SharedComponentDescriptor &componentDescriptor = (*this)[componentName]; RawProps rawProps = rawPropsFromDynamic(props); - SharedShadowNode shadowNode = - componentDescriptor->createShadowNode({ - .tag = tag, - .rootTag = rootTag, - .eventEmitter = componentDescriptor->createEventEmitter(std::move(eventTarget), tag), - .props = componentDescriptor->cloneProps(nullptr, rawProps) - }); + SharedShadowNode shadowNode = componentDescriptor->createShadowNode( + {.tag = tag, + .rootTag = rootTag, + .eventEmitter = + componentDescriptor->createEventEmitter(std::move(eventTarget), tag), + .props = componentDescriptor->cloneProps(nullptr, rawProps)}); return shadowNode; } diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 73767281f81ddd..82ef1d8a9d7589 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -123,8 +123,14 @@ void FabricUIManager::stopSurface(SurfaceId surfaceId) const { (*executor_)([this, surfaceId] { stopSurfaceFunction_(surfaceId); }); } -SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int rootTag, folly::dynamic props, SharedEventTarget eventTarget) const { - SharedShadowNode shadowNode = componentDescriptorRegistry_->createNode(tag, viewName, rootTag, props, eventTarget); +SharedShadowNode FabricUIManager::createNode( + int tag, + std::string viewName, + int rootTag, + folly::dynamic props, + SharedEventTarget eventTarget) const { + SharedShadowNode shadowNode = componentDescriptorRegistry_->createNode( + tag, viewName, rootTag, props, eventTarget); if (delegate_) { delegate_->uiManagerDidCreateShadowNode(shadowNode); } diff --git a/ReactCommon/fabric/uimanager/JSIFabricUIManager.cpp b/ReactCommon/fabric/uimanager/JSIFabricUIManager.cpp index 773ee76ba9008b..751498736646ad 100644 --- a/ReactCommon/fabric/uimanager/JSIFabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/JSIFabricUIManager.cpp @@ -2,8 +2,8 @@ #include "JSIFabricUIManager.h" -#include #include +#include #include namespace facebook { @@ -11,162 +11,236 @@ namespace react { namespace { -struct EventTargetWrapper: public EventTarget { - EventTargetWrapper(jsi::WeakObject instanceHandle): - instanceHandle(std::move(instanceHandle)) {} +struct EventTargetWrapper : public EventTarget { + EventTargetWrapper(jsi::WeakObject instanceHandle) + : instanceHandle(std::move(instanceHandle)) {} mutable jsi::WeakObject instanceHandle; }; -struct EventHandlerWrapper: public EventHandler { - EventHandlerWrapper(jsi::Function eventHandler): - callback(std::move(eventHandler)) {} +struct EventHandlerWrapper : public EventHandler { + EventHandlerWrapper(jsi::Function eventHandler) + : callback(std::move(eventHandler)) {} jsi::Function callback; }; -struct ShadowNodeWrapper: public jsi::HostObject { - ShadowNodeWrapper(SharedShadowNode shadowNode): - shadowNode(std::move(shadowNode)) {} +struct ShadowNodeWrapper : public jsi::HostObject { + ShadowNodeWrapper(SharedShadowNode shadowNode) + : shadowNode(std::move(shadowNode)) {} SharedShadowNode shadowNode; }; -struct ShadowNodeListWrapper: public jsi::HostObject { - ShadowNodeListWrapper(SharedShadowNodeUnsharedList shadowNodeList): - shadowNodeList(shadowNodeList) {} +struct ShadowNodeListWrapper : public jsi::HostObject { + ShadowNodeListWrapper(SharedShadowNodeUnsharedList shadowNodeList) + : shadowNodeList(shadowNodeList) {} SharedShadowNodeUnsharedList shadowNodeList; }; -jsi::Value createNode(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { +jsi::Value createNode( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { auto reactTag = (Tag)arguments[0].getNumber(); auto viewName = arguments[1].getString(runtime).utf8(runtime); auto rootTag = (Tag)arguments[2].getNumber(); - auto props = folly::dynamic {arguments[3].isNull() ? nullptr : jsi::dynamicFromValue(runtime, arguments[3])}; - auto eventTarget = std::make_shared(jsi::WeakObject(runtime, arguments[4].getObject(runtime))); + auto props = folly::dynamic{ + arguments[3].isNull() ? nullptr + : jsi::dynamicFromValue(runtime, arguments[3])}; + auto eventTarget = std::make_shared( + jsi::WeakObject(runtime, arguments[4].getObject(runtime))); - SharedShadowNode node = uiManager.createNode( - reactTag, - viewName, - rootTag, - props, - eventTarget - ); + SharedShadowNode node = + uiManager.createNode(reactTag, viewName, rootTag, props, eventTarget); auto shadowNodeWrapper = std::make_shared(node); return jsi::Object::createFromHostObject(runtime, shadowNodeWrapper); } -jsi::Value cloneNode(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - auto previousNode = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value cloneNode( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + auto previousNode = arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; auto newNode = uiManager.cloneNode(previousNode); auto wrapper = std::make_shared(std::move(newNode)); return jsi::Object::createFromHostObject(runtime, std::move(wrapper)); } -jsi::Value cloneNodeWithNewChildren(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - auto previousNode = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value cloneNodeWithNewChildren( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + auto previousNode = arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; auto newNode = uiManager.cloneNodeWithNewChildren(previousNode); auto wrapper = std::make_shared(std::move(newNode)); return jsi::Object::createFromHostObject(runtime, std::move(wrapper)); } -jsi::Value cloneNodeWithNewProps(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - auto previousNode = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value cloneNodeWithNewProps( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + auto previousNode = arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; auto props = dynamicFromValue(runtime, arguments[1]); auto newNode = uiManager.cloneNodeWithNewProps(previousNode, props); auto wrapper = std::make_shared(std::move(newNode)); return jsi::Object::createFromHostObject(runtime, std::move(wrapper)); } -jsi::Value cloneNodeWithNewChildrenAndProps(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - auto previousNode = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value cloneNodeWithNewChildrenAndProps( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + auto previousNode = arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; auto props = dynamicFromValue(runtime, arguments[1]); - auto newNode = uiManager.cloneNodeWithNewChildrenAndProps(previousNode, props); + auto newNode = + uiManager.cloneNodeWithNewChildrenAndProps(previousNode, props); auto wrapper = std::make_shared(std::move(newNode)); return jsi::Object::createFromHostObject(runtime, std::move(wrapper)); } -jsi::Value appendChild(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - auto parentNode = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNode; - auto childNode = arguments[1].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value appendChild( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + auto parentNode = arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; + auto childNode = arguments[1] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; uiManager.appendChild(parentNode, childNode); return jsi::Value::undefined(); } -jsi::Value createChildSet(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { +jsi::Value createChildSet( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { auto rootTag = (Tag)arguments[0].getNumber(); SharedShadowNodeUnsharedList childSet = uiManager.createChildSet(rootTag); return jsi::Object::createFromHostObject( - runtime, - std::make_unique(childSet) - ); + runtime, std::make_unique(childSet)); } -jsi::Value appendChildToSet(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { - SharedShadowNodeUnsharedList childSet = arguments[0].getObject(runtime).getHostObject(runtime)->shadowNodeList; - SharedShadowNode childNode = arguments[1].getObject(runtime).getHostObject(runtime)->shadowNode; +jsi::Value appendChildToSet( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { + SharedShadowNodeUnsharedList childSet = + arguments[0] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNodeList; + SharedShadowNode childNode = arguments[1] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNode; uiManager.appendChildToSet(childSet, childNode); return jsi::Value::undefined(); } -jsi::Value completeRoot(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { +jsi::Value completeRoot( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { auto rootTag = (Tag)arguments[0].getNumber(); - SharedShadowNodeUnsharedList childSet = arguments[1].getObject(runtime).getHostObject(runtime)->shadowNodeList; + SharedShadowNodeUnsharedList childSet = + arguments[1] + .getObject(runtime) + .getHostObject(runtime) + ->shadowNodeList; uiManager.completeRoot(rootTag, childSet); return jsi::Value::undefined(); } -jsi::Value registerEventHandler(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) { +jsi::Value registerEventHandler( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count) { auto eventHandler = arguments[0].getObject(runtime).getFunction(runtime); - auto eventHandlerWrapper = std::make_unique(std::move(eventHandler)); + auto eventHandlerWrapper = + std::make_unique(std::move(eventHandler)); uiManager.registerEventHandler(std::move(eventHandlerWrapper)); return jsi::Value::undefined(); } -using Callback = jsi::Value (const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count); +using Callback = jsi::Value( + const UIManager &uiManager, + jsi::Runtime &runtime, + const jsi::Value *arguments, + size_t count); void addMethod( - const UIManager &uiManager, - jsi::Runtime &runtime, - jsi::Object &module, - const char *name, - Callback &callback -) { + const UIManager &uiManager, + jsi::Runtime &runtime, + jsi::Object &module, + const char *name, + Callback &callback) { module.setProperty( - runtime, - name, - jsi::Function::createFromHostFunction( runtime, - jsi::PropNameID::forAscii(runtime, name), - 1, - [&uiManager, &callback](jsi::Runtime &runtime, const jsi::Value &value, const jsi::Value *args, size_t count) { - return callback(uiManager, runtime, args, count); - } - ) - ); + name, + jsi::Function::createFromHostFunction( + runtime, + jsi::PropNameID::forAscii(runtime, name), + 1, + [&uiManager, &callback]( + jsi::Runtime &runtime, + const jsi::Value &value, + const jsi::Value *args, + size_t count) { + return callback(uiManager, runtime, args, count); + })); } void removeMethod( - jsi::Runtime &runtime, - jsi::Object &module, - const char *name -) { + jsi::Runtime &runtime, + jsi::Object &module, + const char *name) { // Step 1: Find and replace the body of the method with noop. auto propertyValue = module.getProperty(runtime, name); auto propertyObject = propertyValue.asObject(runtime); auto propertyFunction = propertyObject.asFunction(runtime); auto &propertyHostFunction = propertyFunction.getHostFunction(runtime); - propertyHostFunction = [](jsi::Runtime& runtime, const jsi::Value& thisVal, const jsi::Value* args, size_t count) { + propertyHostFunction = [](jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count) { // Noop. return jsi::Value::undefined(); }; @@ -176,78 +250,113 @@ void removeMethod( } jsi::Object getModule(jsi::Runtime &runtime, const std::string &moduleName) { - auto batchedBridge = runtime.global().getPropertyAsObject(runtime, "__fbBatchedBridge"); - auto getCallableModule = batchedBridge.getPropertyAsFunction(runtime, "getCallableModule"); - auto module = getCallableModule.callWithThis(runtime, batchedBridge, { jsi::String::createFromUtf8(runtime, moduleName) }).asObject(runtime); + auto batchedBridge = + runtime.global().getPropertyAsObject(runtime, "__fbBatchedBridge"); + auto getCallableModule = + batchedBridge.getPropertyAsFunction(runtime, "getCallableModule"); + auto module = getCallableModule + .callWithThis( + runtime, + batchedBridge, + {jsi::String::createFromUtf8(runtime, moduleName)}) + .asObject(runtime); return module; } } // namespace void JSIDispatchFabricEventToEmptyTarget( - jsi::Runtime &runtime, - const EventHandler &eventHandler, - const std::string &type, - const folly::dynamic &payload -) { - auto &eventHandlerWrapper = static_cast(eventHandler); - eventHandlerWrapper.callback.call(runtime, { - jsi::Value::null(), - jsi::String::createFromUtf8(runtime, type), - jsi::valueFromDynamic(runtime, payload) - }); + jsi::Runtime &runtime, + const EventHandler &eventHandler, + const std::string &type, + const folly::dynamic &payload) { + auto &eventHandlerWrapper = + static_cast(eventHandler); + eventHandlerWrapper.callback.call( + runtime, + {jsi::Value::null(), + jsi::String::createFromUtf8(runtime, type), + jsi::valueFromDynamic(runtime, payload)}); } void JSIDispatchFabricEventToTarget( - jsi::Runtime &runtime, - const EventHandler &eventHandler, - const EventTarget &eventTarget, - const std::string &type, - const folly::dynamic &payload -) { - auto &eventHandlerWrapper = static_cast(eventHandler); - auto &eventTargetWrapper = static_cast(eventTarget); + jsi::Runtime &runtime, + const EventHandler &eventHandler, + const EventTarget &eventTarget, + const std::string &type, + const folly::dynamic &payload) { + auto &eventHandlerWrapper = + static_cast(eventHandler); + auto &eventTargetWrapper = + static_cast(eventTarget); auto eventTargetValue = eventTargetWrapper.instanceHandle.lock(runtime); if (eventTargetValue.isUndefined()) { return; } - eventHandlerWrapper.callback.call(runtime, { - std::move(eventTargetValue), - jsi::String::createFromUtf8(runtime, type), - jsi::valueFromDynamic(runtime, payload) - }); + eventHandlerWrapper.callback.call( + runtime, + {std::move(eventTargetValue), + jsi::String::createFromUtf8(runtime, type), + jsi::valueFromDynamic(runtime, payload)}); } const char *kUIManagerModuleName = "nativeFabricUIManager"; -void JSIInstallFabricUIManager( - jsi::Runtime &runtime, - UIManager &uiManager -) { +void JSIInstallFabricUIManager(jsi::Runtime &runtime, UIManager &uiManager) { auto module = jsi::Object(runtime); addMethod(uiManager, runtime, module, "createNode", createNode); addMethod(uiManager, runtime, module, "cloneNode", cloneNode); - addMethod(uiManager, runtime, module, "cloneNodeWithNewChildren", cloneNodeWithNewChildren); - addMethod(uiManager, runtime, module, "cloneNodeWithNewProps", cloneNodeWithNewProps); - addMethod(uiManager, runtime, module, "cloneNodeWithNewChildrenAndProps", cloneNodeWithNewChildrenAndProps); + addMethod( + uiManager, + runtime, + module, + "cloneNodeWithNewChildren", + cloneNodeWithNewChildren); + addMethod( + uiManager, + runtime, + module, + "cloneNodeWithNewProps", + cloneNodeWithNewProps); + addMethod( + uiManager, + runtime, + module, + "cloneNodeWithNewChildrenAndProps", + cloneNodeWithNewChildrenAndProps); addMethod(uiManager, runtime, module, "appendChild", appendChild); addMethod(uiManager, runtime, module, "createChildSet", createChildSet); addMethod(uiManager, runtime, module, "appendChildToSet", appendChildToSet); addMethod(uiManager, runtime, module, "completeRoot", completeRoot); - addMethod(uiManager, runtime, module, "registerEventHandler", registerEventHandler); - - uiManager.setDispatchEventToEmptyTargetFunction([&runtime](const EventHandler &eventHandler, const std::string &type, const folly::dynamic &payload) { - return JSIDispatchFabricEventToEmptyTarget(runtime, eventHandler, type, payload); - }); - - uiManager.setDispatchEventToTargetFunction([&runtime](const EventHandler &eventHandler, const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload) { - return JSIDispatchFabricEventToTarget(runtime, eventHandler, eventTarget, type, payload); - }); - - uiManager.setStartSurfaceFunction([&runtime](SurfaceId surfaceId, const std::string &moduleName, const folly::dynamic &initialProps) { + addMethod( + uiManager, runtime, module, "registerEventHandler", registerEventHandler); + + uiManager.setDispatchEventToEmptyTargetFunction( + [&runtime]( + const EventHandler &eventHandler, + const std::string &type, + const folly::dynamic &payload) { + return JSIDispatchFabricEventToEmptyTarget( + runtime, eventHandler, type, payload); + }); + + uiManager.setDispatchEventToTargetFunction( + [&runtime]( + const EventHandler &eventHandler, + const EventTarget &eventTarget, + const std::string &type, + const folly::dynamic &payload) { + return JSIDispatchFabricEventToTarget( + runtime, eventHandler, eventTarget, type, payload); + }); + + uiManager.setStartSurfaceFunction([&runtime]( + SurfaceId surfaceId, + const std::string &moduleName, + const folly::dynamic &initialProps) { return JSIStartSurface(runtime, surfaceId, moduleName, initialProps); }); @@ -258,10 +367,9 @@ void JSIInstallFabricUIManager( runtime.global().setProperty(runtime, kUIManagerModuleName, module); } -void JSIUninstallFabricUIManager( - jsi::Runtime &runtime -) { - auto module = runtime.global().getPropertyAsObject(runtime, kUIManagerModuleName); +void JSIUninstallFabricUIManager(jsi::Runtime &runtime) { + auto module = + runtime.global().getPropertyAsObject(runtime, kUIManagerModuleName); removeMethod(runtime, module, "createNode"); removeMethod(runtime, module, "cloneNode"); @@ -278,11 +386,10 @@ void JSIUninstallFabricUIManager( } void JSIStartSurface( - jsi::Runtime &runtime, - SurfaceId surfaceId, - const std::string &moduleName, - const folly::dynamic &initalProps -) { + jsi::Runtime &runtime, + SurfaceId surfaceId, + const std::string &moduleName, + const folly::dynamic &initalProps) { folly::dynamic parameters = folly::dynamic::object(); parameters["rootTag"] = surfaceId; parameters["initialProps"] = initalProps; @@ -290,22 +397,18 @@ void JSIStartSurface( auto module = getModule(runtime, "AppRegistry"); auto method = module.getPropertyAsFunction(runtime, "runApplication"); - method.callWithThis(runtime, module, { - jsi::String::createFromUtf8(runtime, moduleName), - jsi::valueFromDynamic(runtime, parameters) - }); + method.callWithThis( + runtime, + module, + {jsi::String::createFromUtf8(runtime, moduleName), + jsi::valueFromDynamic(runtime, parameters)}); } -void JSIStopSurface( - jsi::Runtime &runtime, - SurfaceId surfaceId -) { +void JSIStopSurface(jsi::Runtime &runtime, SurfaceId surfaceId) { auto module = getModule(runtime, "ReactFabric"); auto method = module.getPropertyAsFunction(runtime, "unmountComponentAtNode"); - method.callWithThis(runtime, module, { - jsi::Value {surfaceId} - }); + method.callWithThis(runtime, module, {jsi::Value{surfaceId}}); } } // namespace react diff --git a/ReactCommon/fabric/uimanager/JSIFabricUIManager.h b/ReactCommon/fabric/uimanager/JSIFabricUIManager.h index c1a1e47c1392a7..fd1b7b74d0dca6 100644 --- a/ReactCommon/fabric/uimanager/JSIFabricUIManager.h +++ b/ReactCommon/fabric/uimanager/JSIFabricUIManager.h @@ -10,40 +10,29 @@ namespace facebook { namespace react { void JSIDispatchFabricEventToEmptyTarget( - jsi::Runtime &runtime, - const EventHandler &eventHandler, - const std::string &type, - const folly::dynamic &payload -); + jsi::Runtime &runtime, + const EventHandler &eventHandler, + const std::string &type, + const folly::dynamic &payload); void JSIDispatchFabricEventToTarget( - jsi::Runtime &runtime, - const EventHandler &eventHandler, - const EventTarget &eventTarget, - const std::string &type, - const folly::dynamic &payload -); - -void JSIInstallFabricUIManager( - jsi::Runtime &runtime, - UIManager &uiManager -); - -void JSIUninstallFabricUIManager( - jsi::Runtime &runtime -); + jsi::Runtime &runtime, + const EventHandler &eventHandler, + const EventTarget &eventTarget, + const std::string &type, + const folly::dynamic &payload); + +void JSIInstallFabricUIManager(jsi::Runtime &runtime, UIManager &uiManager); + +void JSIUninstallFabricUIManager(jsi::Runtime &runtime); void JSIStartSurface( - jsi::Runtime &runtime, - SurfaceId surfaceId, - const std::string &moduleName, - const folly::dynamic &initalProps -); - -void JSIStopSurface( - jsi::Runtime &runtime, - SurfaceId surfaceId -); - -} -} + jsi::Runtime &runtime, + SurfaceId surfaceId, + const std::string &moduleName, + const folly::dynamic &initalProps); + +void JSIStopSurface(jsi::Runtime &runtime, SurfaceId surfaceId); + +} // namespace react +} // namespace facebook