mirror of
https://github.com/status-im/react-native.git
synced 2025-02-22 14:18:23 +00:00
more lint auto fixing
Summary: ran `find js/react-native-github/ReactCommon | xargs arc lint -a` Reviewed By: fkgozali Differential Revision: D12902865 fbshipit-source-id: 9c68c0f7e28893e76df966ad4110299e89895454
This commit is contained in:
parent
81e5d64bfe
commit
10d41d4225
@ -7,16 +7,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/attributedstring/primitives.h>
|
||||
#include <fabric/attributedstring/AttributedString.h>
|
||||
#include <fabric/attributedstring/ParagraphAttributes.h>
|
||||
#include <fabric/attributedstring/TextAttributes.h>
|
||||
#include <fabric/core/conversions.h>
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/attributedstring/primitives.h>
|
||||
#include <fabric/core/LayoutableShadowNode.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
#include <fabric/core/conversions.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
#include <folly/dynamic.h>
|
||||
|
||||
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(
|
||||
|
@ -15,8 +15,7 @@ const char ViewComponentName[] = "View";
|
||||
bool ViewShadowNode::isLayoutOnly() const {
|
||||
const auto &viewProps = *std::static_pointer_cast<const ViewProps>(props_);
|
||||
|
||||
return
|
||||
viewProps.collapsable &&
|
||||
return viewProps.collapsable &&
|
||||
// Event listeners
|
||||
!viewProps.onLayout &&
|
||||
// Generic Props
|
||||
|
@ -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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
|
||||
- (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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
|
||||
// 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 @@ typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
|
||||
|
||||
- (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;
|
||||
}
|
||||
[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);
|
||||
CGFloat fontSize =
|
||||
MAX(MIN(font.pointSize * ratio, maximumFontSize),
|
||||
minimumFontSize);
|
||||
|
||||
[self addAttribute:NSFontAttributeName
|
||||
value:[font fontWithSize:fontSize]
|
||||
range:range];
|
||||
}
|
||||
];
|
||||
[self addAttribute:NSFontAttributeName
|
||||
value:[font fontWithSize:fontSize]
|
||||
range:range];
|
||||
}];
|
||||
|
||||
[self endEditing];
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ static UIFont *RCTDefaultFontWithFontProperties(
|
||||
|
||||
fontDescriptor =
|
||||
[fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
|
||||
font =
|
||||
[UIFont fontWithDescriptor:fontDescriptor size:fontProperties.size];
|
||||
font = [UIFont fontWithDescriptor:fontDescriptor
|
||||
size:fontProperties.size];
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "JSIFabricUIManager.h"
|
||||
|
||||
#include <fabric/uimanager/FabricUIManager.h>
|
||||
#include <fabric/core/ShadowNode.h>
|
||||
#include <fabric/uimanager/FabricUIManager.h>
|
||||
#include <jsi/JSIDynamic.h>
|
||||
|
||||
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<EventTargetWrapper>(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<EventTargetWrapper>(
|
||||
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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(runtime)
|
||||
->shadowNode;
|
||||
auto newNode = uiManager.cloneNode(previousNode);
|
||||
auto wrapper = std::make_shared<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(runtime)
|
||||
->shadowNode;
|
||||
auto newNode = uiManager.cloneNodeWithNewChildren(previousNode);
|
||||
auto wrapper = std::make_shared<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(runtime)
|
||||
->shadowNode;
|
||||
auto props = dynamicFromValue(runtime, arguments[1]);
|
||||
auto newNode = uiManager.cloneNodeWithNewProps(previousNode, props);
|
||||
auto wrapper = std::make_shared<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(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<ShadowNodeWrapper>(runtime)->shadowNode;
|
||||
auto childNode = arguments[1].getObject(runtime).getHostObject<ShadowNodeWrapper>(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<ShadowNodeWrapper>(runtime)
|
||||
->shadowNode;
|
||||
auto childNode = arguments[1]
|
||||
.getObject(runtime)
|
||||
.getHostObject<ShadowNodeWrapper>(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<ShadowNodeListWrapper>(childSet)
|
||||
);
|
||||
runtime, std::make_unique<ShadowNodeListWrapper>(childSet));
|
||||
}
|
||||
|
||||
jsi::Value appendChildToSet(const UIManager &uiManager, jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) {
|
||||
SharedShadowNodeUnsharedList childSet = arguments[0].getObject(runtime).getHostObject<ShadowNodeListWrapper>(runtime)->shadowNodeList;
|
||||
SharedShadowNode childNode = arguments[1].getObject(runtime).getHostObject<ShadowNodeWrapper>(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<ShadowNodeListWrapper>(runtime)
|
||||
->shadowNodeList;
|
||||
SharedShadowNode childNode = arguments[1]
|
||||
.getObject(runtime)
|
||||
.getHostObject<ShadowNodeWrapper>(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<ShadowNodeListWrapper>(runtime)->shadowNodeList;
|
||||
SharedShadowNodeUnsharedList childSet =
|
||||
arguments[1]
|
||||
.getObject(runtime)
|
||||
.getHostObject<ShadowNodeListWrapper>(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<EventHandlerWrapper>(std::move(eventHandler));
|
||||
auto eventHandlerWrapper =
|
||||
std::make_unique<EventHandlerWrapper>(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<const EventHandlerWrapper &>(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<const EventHandlerWrapper &>(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<const EventHandlerWrapper &>(eventHandler);
|
||||
auto &eventTargetWrapper = static_cast<const EventTargetWrapper &>(eventTarget);
|
||||
jsi::Runtime &runtime,
|
||||
const EventHandler &eventHandler,
|
||||
const EventTarget &eventTarget,
|
||||
const std::string &type,
|
||||
const folly::dynamic &payload) {
|
||||
auto &eventHandlerWrapper =
|
||||
static_cast<const EventHandlerWrapper &>(eventHandler);
|
||||
auto &eventTargetWrapper =
|
||||
static_cast<const EventTargetWrapper &>(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);
|
||||
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.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.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) {
|
||||
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
|
||||
|
@ -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
|
||||
);
|
||||
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 JSIInstallFabricUIManager(jsi::Runtime &runtime, UIManager &uiManager);
|
||||
|
||||
void JSIUninstallFabricUIManager(
|
||||
jsi::Runtime &runtime
|
||||
);
|
||||
void JSIUninstallFabricUIManager(jsi::Runtime &runtime);
|
||||
|
||||
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);
|
||||
|
||||
void JSIStopSurface(
|
||||
jsi::Runtime &runtime,
|
||||
SurfaceId surfaceId
|
||||
);
|
||||
void JSIStopSurface(jsi::Runtime &runtime, SurfaceId surfaceId);
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
Loading…
x
Reference in New Issue
Block a user