Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
#include "core/renderer/ui_wrapper/painting/native_painting_context.h"

@protocol LUIBodyView;
@class LynxComponentScopeRegistry;

namespace lynx {
namespace tasm {

class PaintImage;
class NativePaintingCtxDarwin : public PaintingCtxPlatformImpl, public NativePaintingContext {
public:
NativePaintingCtxDarwin(LynxUIOwner *owner, void *textra);
NativePaintingCtxDarwin(LynxUIOwner *owner, LynxComponentScopeRegistry *component_registry,
void *textra);
~NativePaintingCtxDarwin() override = default;

NativePaintingCtxDarwin(const NativePaintingCtxDarwin &) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@

} // namespace

NativePaintingCtxDarwin::NativePaintingCtxDarwin(LynxUIOwner *owner, void *textra)
: context_(
std::make_unique<PlatformRendererContextDarwin>([owner tryGetContainerView], owner)) {
NativePaintingCtxDarwin::NativePaintingCtxDarwin(LynxUIOwner *owner,
LynxComponentScopeRegistry *component_registry,
void *textra)
: context_(std::make_unique<PlatformRendererContextDarwin>([owner tryGetContainerView], owner,
component_registry)) {
platform_ref_ = std::make_shared<NativePaintingCtxPlatformDarwinRef>(
std::make_unique<PlatformRendererDarwinFactory>(context_.get()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)testNativePaintingContextMarksPaintEndTiming {
componentRegistry:nil
screenMetrics:nil];
auto nativePaintingContext =
std::make_unique<lynx::tasm::NativePaintingCtxDarwin>(uiOwner, nullptr);
std::make_unique<lynx::tasm::NativePaintingCtxDarwin>(uiOwner, nil, nullptr);
lynx::fml::MessageLoop::EnsureInitializedForCurrentThread();
auto queue = std::make_shared<lynx::shell::DynamicUIOperationQueue>(
lynx::base::ThreadStrategyForRendering::ALL_ON_UI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#import <UIKit/UIKit.h>

@protocol LUIBodyView;
@class LynxComponentScopeRegistry;
@class LynxUIOwner;

namespace lynx {
namespace tasm {

class PlatformRendererContextDarwin {
public:
PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view, LynxUIOwner* ui_owner = nil);
PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view, LynxUIOwner* ui_owner = nil,
LynxComponentScopeRegistry* component_registry = nil);
~PlatformRendererContextDarwin();

UIView<LUIBodyView>* GetContainerView() { return renderer_context_.bodyView; }
Expand All @@ -25,12 +27,15 @@ class PlatformRendererContextDarwin {

LynxUIOwner* GetUIOwner() { return ui_owner_; }

LynxComponentScopeRegistry* GetComponentRegistry() { return component_registry_; }

CGPoint GetRootViewLocationOnScreen();
CGSize GetScreenSize();

private:
LynxRendererContext* renderer_context_;
LynxUIOwner* ui_owner_;
LynxComponentScopeRegistry* component_registry_;
};

} // namespace tasm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
#include "core/renderer/ui_wrapper/painting/ios/platform_renderer_context_darwin.h"

#import <Lynx/LUIBodyView.h>
#import <Lynx/LynxComponentRegistry.h>
#import <Lynx/LynxUIOwner.h>

namespace lynx {
namespace tasm {
PlatformRendererContextDarwin::PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view,
LynxUIOwner* ui_owner)
: ui_owner_(ui_owner) {
PlatformRendererContextDarwin::PlatformRendererContextDarwin(
UIView<LUIBodyView>* container_view, LynxUIOwner* ui_owner,
LynxComponentScopeRegistry* component_registry)
: ui_owner_(ui_owner), component_registry_(component_registry) {
renderer_context_ = [[LynxRendererContext alloc] init];
renderer_context_.bodyView = container_view;
}

PlatformRendererContextDarwin::~PlatformRendererContextDarwin() {
renderer_context_ = nil;
ui_owner_ = nil;
component_registry_ = nil;
}

CGPoint PlatformRendererContextDarwin::GetRootViewLocationOnScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ bool ShouldDetachThroughUIOwner(LynxUIOwner* owner, int sign) {
if (IsPlatformExtendedRenderer()) {
base::String extended_tag_name = GetExtendedRendererTagName();
NSString* tagName = [NSString stringWithUTF8String:extended_tag_name.str().c_str()];
Class hostClass = [LynxComponentRegistry rendererHostClassWithName:tagName];
LynxComponentScopeRegistry* componentRegistry = context_->GetComponentRegistry();
Class hostClass = componentRegistry != nil
? [componentRegistry rendererHostClassWithName:tagName]
: [LynxComponentRegistry rendererHostClassWithName:tagName];
auto initial_prop_bundle = CreateDarwinPropBundle(init_data);
NSDictionary* initial_props = initial_prop_bundle ? initial_prop_bundle->dictionary() : nil;

Expand Down
32 changes: 17 additions & 15 deletions core/renderer/ui_wrapper/painting/ios/ui_delegate_darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@

#include "core/public/ui_delegate.h"

@class LynxComponentScopeRegistry;

namespace lynx {
namespace tasm {

class UIDelegateDarwin : public UIDelegate {
public:
UIDelegateDarwin(LynxUIOwner* ui_owner, bool use_native_painting_context,
void* textra, bool enable_create_ui_async,
UIDelegateDarwin(LynxUIOwner* ui_owner, LynxComponentScopeRegistry* component_registry,
bool use_native_painting_context, void* textra, bool enable_create_ui_async,
LynxShadowNodeOwner* shadow_node_owner)
: ui_owner_(ui_owner),
component_registry_(component_registry),
use_native_painting_context_(use_native_painting_context),
textra_(textra),
enable_create_ui_async_(enable_create_ui_async),
Expand All @@ -34,25 +37,24 @@ class UIDelegateDarwin : public UIDelegate {

bool UsesLogicalPixels() const override { return true; }

std::unique_ptr<runtime::NativeModuleFactory> GetCustomModuleFactory()
override {
std::unique_ptr<runtime::NativeModuleFactory> GetCustomModuleFactory() override {
// TODO(chenyouhui): Implement this after unify lepus module and js module.
return nullptr;
}
void OnLynxCreate(
const std::shared_ptr<shell::ListEngineProxy>& list_engine_proxy,
const std::shared_ptr<shell::LynxEngineProxy>& engine_proxy,
const std::shared_ptr<shell::LynxRuntimeProxy>& runtime_proxy,
const std::shared_ptr<shell::LynxLayoutProxy>& layout_proxy,
const std::shared_ptr<shell::PerfControllerProxy>& perf_controller_proxy,
const std::shared_ptr<shell::EventTrackerProxy>& event_tracker_proxy,
const std::shared_ptr<pub::LynxResourceLoader>& resource_loader,
const fml::RefPtr<fml::TaskRunner>& ui_task_runner,
const fml::RefPtr<fml::TaskRunner>& layout_task_runner,
int32_t instance_id, bool is_embedded_mode = false) override;
void OnLynxCreate(const std::shared_ptr<shell::ListEngineProxy>& list_engine_proxy,
const std::shared_ptr<shell::LynxEngineProxy>& engine_proxy,
const std::shared_ptr<shell::LynxRuntimeProxy>& runtime_proxy,
const std::shared_ptr<shell::LynxLayoutProxy>& layout_proxy,
const std::shared_ptr<shell::PerfControllerProxy>& perf_controller_proxy,
const std::shared_ptr<shell::EventTrackerProxy>& event_tracker_proxy,
const std::shared_ptr<pub::LynxResourceLoader>& resource_loader,
const fml::RefPtr<fml::TaskRunner>& ui_task_runner,
const fml::RefPtr<fml::TaskRunner>& layout_task_runner, int32_t instance_id,
bool is_embedded_mode = false) override;

private:
__weak LynxUIOwner* ui_owner_;
__strong LynxComponentScopeRegistry* component_registry_;
bool use_native_painting_context_;
void* textra_{nullptr};
bool enable_create_ui_async_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

std::unique_ptr<PaintingCtxPlatformImpl> UIDelegateDarwin::CreatePaintingContext() {
if (use_native_painting_context_) {
return std::make_unique<NativePaintingCtxDarwin>(ui_owner_, textra_);
return std::make_unique<NativePaintingCtxDarwin>(ui_owner_, component_registry_, textra_);
}
return std::make_unique<PaintingContextDarwin>(ui_owner_, enable_create_ui_async_, textra_);
}
Expand Down
7 changes: 5 additions & 2 deletions platform/darwin/ios/lynx/LynxUIRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import <Lynx/DevToolOverlayDelegate.h>
#import <Lynx/LUIConfigAdapter.h>
#import <Lynx/ListNodeInfoFetcher.h>
#import <Lynx/LynxComponentRegistry.h>
#import <Lynx/LynxContext+Internal.h>
#import <Lynx/LynxEnv+Internal.h>
#import <Lynx/LynxEventHandler+Internal.h>
Expand Down Expand Up @@ -85,6 +86,7 @@ @implementation LynxUIRenderer {
__weak LynxContext *_lynxContext;
LynxProviderRegistry *_providerRegistry;
std::unique_ptr<lynx::tasm::UIDelegate> ui_delegate_;
LynxComponentScopeRegistry *_componentRegistry;
LynxUIOwner *_uiOwner;

void *_textra;
Expand All @@ -107,6 +109,7 @@ - (instancetype)initWithLynxContext:(LynxContext *)context
_lynxContext = context;
_containerView = containerView;
_providerRegistry = providerRegistry;
_componentRegistry = builder.config.componentRegistry;
_textra = 0;
_enableGenericResourceLoader =
[self checkEnableGenericResourceFetcher:builder.enableGenericResourceFetcher];
Expand All @@ -121,7 +124,7 @@ - (void)setupUIOwnerWithBuilder:(LynxViewBuilder *)builder {
[[LynxScreenMetrics alloc] initWithScreenSize:builder.screenSize
scale:[UIScreen mainScreen].scale];
_uiOwner = [[LynxUIOwner alloc] initWithContainerView:_containerView
componentRegistry:builder.config.componentRegistry
componentRegistry:_componentRegistry
screenMetrics:screenMetrics
errorHandler:_containerView
uiConfig:nil
Expand Down Expand Up @@ -182,7 +185,7 @@ - (void)setupUIDelegate:(LynxShadowNodeOwner *)owner {
_textra = [textService createTextLayoutAPIFromContext:_uiOwner];
}
ui_delegate_ = std::make_unique<lynx::tasm::UIDelegateDarwin>(
_uiOwner, _lynxContext.isFragmentLayerRenderOn, _textra,
_uiOwner, _componentRegistry, _lynxContext.isFragmentLayerRenderOn, _textra,
[[LynxEnv sharedInstance] enableCreateUIAsync], owner);
}

Expand Down
18 changes: 18 additions & 0 deletions platform/darwin/ios/lynx/renderer/LynxRendererUnitTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// LICENSE file in the root directory of this source tree.

#import <Lynx/LynxCSSType.h>
#import <Lynx/LynxComponentRegistry.h>
#import <Lynx/LynxContainerView.h>
#import <Lynx/LynxDisplayListApplier+Internal.h>
#import <Lynx/LynxRenderer+Internal.h>
Expand All @@ -26,6 +27,12 @@ - (void)ensureLynxDisplayListApplier;
@interface LynxRendererUnitTest : XCTestCase
@end

@interface LynxScopedRendererHost : LynxContainerView
@end

@implementation LynxScopedRendererHost
@end

@implementation LynxRendererUnitTest

- (void)setUp {
Expand Down Expand Up @@ -250,6 +257,17 @@ - (void)testPlatformRendererDarwinInsertsChildRelativeToNativeSibling {
[parentView.layer.sublayers indexOfObject:thirdView.layer]);
}

- (void)testPlatformRendererDarwinUsesScopedRendererHostRegistry {
NSString* tagName = @"scoped-renderer-host-for-platform-renderer-test";
LynxComponentScopeRegistry* registry = [LynxComponentScopeRegistry new];
[registry registerRendererHost:LynxScopedRendererHost.class withName:tagName];
lynx::tasm::PlatformRendererContextDarwin context(nil, nil, registry);

lynx::tasm::PlatformRendererDarwin renderer(&context, 13, lynx::base::String(tagName.UTF8String));

XCTAssertTrue([renderer.GetUIView() isKindOfClass:LynxScopedRendererHost.class]);
}

- (void)testPlatformRendererDarwinUsesTopLeftAnchorForTransformedLayout {
lynx::tasm::PlatformRendererContextDarwin context(nil);
lynx::tasm::PlatformRendererDarwin renderer(&context, 13, PlatformRendererType::kView);
Expand Down
Loading