Skip to content

Commit 5cbe8b0

Browse files
rAY-ooojianliang00
authored andcommitted
[Optimize][Event][iOS] Make NativeUIRender compatible with custom components.
description: 1. Added renderer host support for NativeUIRender without exposing private renderer headers through public UIView categories. 2. Added cleanupCreatedUI related methods for recycling created UI elements. 3. Adapted PlatformRendererDarwin to handle UI creation, insertion, deletion, and destruction logic. 4. Improved the callback handling process for FinishLayoutOperation and FinishTasmOperation. TEST: xcodebuild build-for-testing ARCHS=arm64 -workspace LynxExplorer.xcworkspace -scheme LynxExplorerTests -enableCodeCoverage YES -configuration Debug -sdk iphonesimulator18.0 COMPILER_INDEX_STORE_ENABLE=NO -derivedDataPath iOSCoreBuild/DerivedData -destination generic/platform=iOS Simulator SYMROOT=Build/Products -testPlan UTTest
1 parent 67d0601 commit 5cbe8b0

23 files changed

Lines changed: 608 additions & 98 deletions

core/renderer/dom/element_manager.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ void ElementManager::OnPatchFinishForFiber(
14591459

14601460
if (root() && root()->EnableFragmentLayerRender()) {
14611461
root()->element_container()->FinishTasmOperation(options);
1462+
root()->element_container()->Flush();
14621463
} else {
14631464
catalyzer_->painting_context()->FinishTasmOperation(options);
14641465
}
@@ -1484,6 +1485,7 @@ void ElementManager::OnPatchFinishForFiber(
14841485
}
14851486
if (root() && root()->EnableFragmentLayerRender()) {
14861487
root()->element_container()->FinishLayoutOperation(options);
1488+
root()->element_container()->Flush();
14871489
} else {
14881490
catalyzer_->painting_context()->FinishLayoutOperation(options);
14891491
}

core/renderer/ui_wrapper/painting/android/native_painting_context_android.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,11 @@ void NativePaintingCtxAndroid::FinishTasmOperation(
296296

297297
void NativePaintingCtxAndroid::FinishLayoutOperation(
298298
const std::shared_ptr<PipelineOptions> &options) {
299-
if (view_manager_ && has_first_screen_) {
299+
if (!has_first_screen_) {
300+
return;
301+
}
302+
303+
if (view_manager_) {
300304
Enqueue([view_manager = view_manager_.get(), options]() {
301305
view_manager->FinishLayoutOperation(options->list_comp_id_,
302306
options->operation_id,

core/renderer/ui_wrapper/painting/android/platform_renderer_android.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ PlatformRendererAndroid::PlatformRendererAndroid(
4141
PlatformRendererContext* context, int id, PlatformRendererType type,
4242
const base::String& tag_name, const fml::RefPtr<PropBundle>& init_data)
4343
: PlatformRendererImpl(id, type, tag_name), context_(context) {
44+
if (ShouldCreatePlatformExtendedRenderer(init_data)) {
45+
is_platform_extended_renderer_ = true;
46+
}
4447
InitializeAndroidView(init_data);
4548
// Register this renderer with the context
4649
if (context_) {
@@ -85,8 +88,7 @@ void PlatformRendererAndroid::InitializeAndroidView(
8588
if (!context_) {
8689
return;
8790
}
88-
if (ShouldCreatePlatformExtendedRenderer(init_data)) {
89-
is_platform_extended_renderer_ = true;
91+
if (IsPlatformExtendedRenderer()) {
9092
const base::String extended_renderer_tag_name =
9193
GetExtendedRendererTagName();
9294
NativePropBundle* native_bundle =
@@ -120,10 +122,8 @@ bool PlatformRendererAndroid::ShouldCreatePlatformExtendedRenderer(
120122
}
121123
if (type_ == PlatformRendererType::kText ||
122124
type_ == PlatformRendererType::kImage ||
123-
type_ == PlatformRendererType::kView) {
124-
return false;
125-
}
126-
if (type_ == PlatformRendererType::kPage) {
125+
type_ == PlatformRendererType::kView ||
126+
type_ == PlatformRendererType::kPage) {
127127
return false;
128128
}
129129
if (type_ != PlatformRendererType::kUnknown) {

core/renderer/ui_wrapper/painting/ios/native_painting_context_darwin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class NativePaintingCtxDarwin : public PaintingCtxPlatformImpl, public NativePai
132132
template <typename F>
133133
void Enqueue(F &&func);
134134

135+
bool has_first_screen_ = false;
135136
std::shared_ptr<shell::DynamicUIOperationQueue> queue_;
136137

137138
std::unique_ptr<PlatformRendererContextDarwin> context_;

core/renderer/ui_wrapper/painting/ios/native_painting_context_darwin.mm

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
namespace tasm {
2727

2828
NativePaintingCtxDarwin::NativePaintingCtxDarwin(LynxUIOwner *owner, void *textra)
29-
: context_(std::make_unique<PlatformRendererContextDarwin>([owner tryGetContainerView])) {
29+
: context_(
30+
std::make_unique<PlatformRendererContextDarwin>([owner tryGetContainerView], owner)) {
3031
platform_ref_ = std::make_shared<NativePaintingCtxPlatformDarwinRef>(
3132
std::make_unique<PlatformRendererDarwinFactory>(context_.get()));
3233

@@ -174,17 +175,41 @@
174175
}
175176

176177
void NativePaintingCtxDarwin::FinishTasmOperation(const std::shared_ptr<PipelineOptions> &options) {
177-
// TODO: impl this function later.
178+
if (queue_ != nullptr &&
179+
options->native_update_data_order_ == queue_->GetNativeUpdateDataOrder()) {
180+
queue_->UpdateStatus(shell::UIOperationStatus::TASM_FINISH);
181+
}
178182
}
179183

180184
void NativePaintingCtxDarwin::FinishLayoutOperation(
181185
const std::shared_ptr<PipelineOptions> &options) {
182-
// TODO: impl this function later.
186+
if (!has_first_screen_) {
187+
return;
188+
}
189+
190+
__weak LynxUIOwner *ui_owner = context_ != nullptr ? context_->GetUIOwner() : nil;
191+
Enqueue(
192+
[ui_owner, weak_queue = std::weak_ptr<shell::DynamicUIOperationQueue>(queue_), options]() {
193+
if (auto queue = weak_queue.lock()) {
194+
[ui_owner finishLayoutOperation:options->operation_id componentID:options->list_comp_id_];
195+
if (options->has_layout) {
196+
[ui_owner layoutDidFinish];
197+
}
198+
if (options->native_update_data_order_ == queue->GetNativeUpdateDataOrder()) {
199+
queue->UpdateStatus(shell::UIOperationStatus::ALL_FINISH);
200+
}
201+
}
202+
});
203+
204+
if (queue_ != nullptr &&
205+
options->native_update_data_order_ == queue_->GetNativeUpdateDataOrder()) {
206+
queue_->UpdateStatus(shell::UIOperationStatus::LAYOUT_FINISH);
207+
}
183208
}
184209

185210
void NativePaintingCtxDarwin::Flush() { queue_->Flush(); }
186211

187-
void NativePaintingCtxDarwin::OnFirstScreen() {}
212+
void NativePaintingCtxDarwin::OnFirstScreen() { has_first_screen_ = true; }
188213

189214
void NativePaintingCtxDarwin::CreatePlatformRenderer(int id, PlatformRendererType type,
190215
const fml::RefPtr<PropBundle> &init_data) {

core/renderer/ui_wrapper/painting/ios/platform_renderer_context_darwin.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
#import <UIKit/UIKit.h>
1010

1111
@protocol LUIBodyView;
12+
@class LynxUIOwner;
1213

1314
namespace lynx {
1415
namespace tasm {
1516

1617
class PlatformRendererContextDarwin {
1718
public:
18-
PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view);
19+
PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view, LynxUIOwner* ui_owner = nil);
1920
~PlatformRendererContextDarwin();
2021

2122
UIView<LUIBodyView>* GetContainerView() { return _renderer_context.bodyView; }
2223

2324
LynxRendererContext* GetRendererContext() { return _renderer_context; }
2425

26+
LynxUIOwner* GetUIOwner() { return _ui_owner; }
27+
2528
CGPoint GetRootViewLocationOnScreen();
2629
CGSize GetScreenSize();
2730

2831
private:
2932
LynxRendererContext* _renderer_context;
33+
LynxUIOwner* _ui_owner;
3034
};
3135

3236
} // namespace tasm

core/renderer/ui_wrapper/painting/ios/platform_renderer_context_darwin.mm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55
#include "core/renderer/ui_wrapper/painting/ios/platform_renderer_context_darwin.h"
66

77
#import <Lynx/LUIBodyView.h>
8+
#import <Lynx/LynxUIOwner.h>
89

910
namespace lynx {
1011
namespace tasm {
11-
PlatformRendererContextDarwin::PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view) {
12+
PlatformRendererContextDarwin::PlatformRendererContextDarwin(UIView<LUIBodyView>* container_view,
13+
LynxUIOwner* ui_owner)
14+
: _ui_owner(ui_owner) {
1215
_renderer_context = [[LynxRendererContext alloc] init];
1316
_renderer_context.bodyView = container_view;
1417
}
1518

16-
PlatformRendererContextDarwin::~PlatformRendererContextDarwin() { _renderer_context = nil; }
19+
PlatformRendererContextDarwin::~PlatformRendererContextDarwin() {
20+
_renderer_context = nil;
21+
_ui_owner = nil;
22+
}
1723

1824
CGPoint PlatformRendererContextDarwin::GetRootViewLocationOnScreen() {
1925
UIView<LUIBodyView>* view = GetContainerView();

core/renderer/ui_wrapper/painting/ios/platform_renderer_darwin.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#import <Lynx/LynxRendererHost.h>
1212
#import <UIKit/UIKit.h>
1313

14+
@class LynxUIOwner;
15+
1416
namespace lynx {
1517

1618
namespace tasm {
@@ -22,12 +24,21 @@ class PlatformRendererDarwin : public PlatformRendererImpl {
2224
public:
2325
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
2426
PlatformRendererType type);
27+
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
28+
PlatformRendererType type,
29+
const fml::RefPtr<PropBundle>& init_data);
2530
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
2631
const base::String& tag_name);
32+
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
33+
const base::String& tag_name,
34+
const fml::RefPtr<PropBundle>& init_data);
2735
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
2836
PlatformRendererType type, const base::String& tag_name);
37+
explicit PlatformRendererDarwin(PlatformRendererContextDarwin* context, int id,
38+
PlatformRendererType type, const base::String& tag_name,
39+
const fml::RefPtr<PropBundle>& init_data);
2940

30-
~PlatformRendererDarwin() override = default;
41+
~PlatformRendererDarwin() override;
3142

3243
// PlatformRendererImpl interface
3344
void OnUpdateDisplayList(DisplayList display_list) override;
@@ -39,13 +50,23 @@ class PlatformRendererDarwin : public PlatformRendererImpl {
3950
void UpdatePlatformExtraBundle(id platform_extra_bundle);
4051

4152
void InitializeUIView();
53+
void InitializeUIView(const fml::RefPtr<PropBundle>& init_data);
4254

4355
UIView<LynxRendererHost>* GetUIView() { return _view; }
4456

4557
private:
58+
bool ShouldCreatePlatformExtendedRenderer(const fml::RefPtr<PropBundle>& init_data) const;
59+
bool InitializeUIOwnerRenderer(const base::String& tag_name,
60+
const fml::RefPtr<PropBundle>& init_data);
61+
void InitializeRendererForView(UIView<LynxRendererHost>* view, NSDictionary* initial_props = nil);
62+
void UpdateUIOwnerLayout(CGRect frame);
63+
bool HasUIOwnerNode(int sign) const;
64+
void CleanupUIView();
65+
4666
UIView<LynxRendererHost>* _view = nil;
4767

4868
PlatformRendererContextDarwin* context_ = nullptr;
69+
LynxUIOwner* ui_owner_ = nil;
4970
};
5071

5172
} // namespace tasm

0 commit comments

Comments
 (0)