Skip to content

Commit d7f1348

Browse files
linxs0211jianliang00
authored andcommitted
[BugFix] Preserve platform renderer child order
- Pass the insertion index through platform renderer AddChild so rebuilt sublayers can insert before existing children. - Measure renderer-backed AndroidView hosts in onMeasure and avoid triggering UIHost measure from onLayout. - Keep the source branch free of temporary diagnostic logging changes. TEST: Android noasan debug example build succeeded. AutoLand: release/3.8, release/3.9, release/4.0, develop
1 parent 690da54 commit d7f1348

11 files changed

Lines changed: 39 additions & 18 deletions

File tree

core/renderer/dom/fragment/fragment_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class TestPlatformRenderer : public PlatformRendererImpl {
9797
}
9898
}
9999
void OnUpdateAttributes(const fml::RefPtr<PropBundle>&, bool) override {}
100-
void OnAddChild(PlatformRenderer*) override {}
100+
void OnAddChild(PlatformRenderer*, int) override {}
101101
void OnRemoveFromParent() override {}
102102
void OnUpdateSubtreeProperties(const DisplayList&) override {}
103103
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ void PlatformRendererAndroid::OnUpdateDisplayList(DisplayList display_list) {
7070
}
7171
}
7272

73-
void PlatformRendererAndroid::OnAddChild(PlatformRenderer* child) {
73+
void PlatformRendererAndroid::OnAddChild(PlatformRenderer* child, int index) {
7474
if (context_ && child) {
7575
context_->InsertPlatformRenderer(PlatformRendererImpl::GetId(),
76-
child->GetId(), -1);
76+
child->GetId(), index);
7777
}
7878
}
7979

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class PlatformRendererAndroid : public PlatformRendererImpl {
3131
void OnUpdateDisplayList(DisplayList display_list) override;
3232
void OnUpdateAttributes(const fml::RefPtr<PropBundle>& attributes,
3333
bool tends_to_flatten) override;
34-
void OnAddChild(PlatformRenderer* child) override;
34+
void OnAddChild(PlatformRenderer* child, int index) override;
3535
void OnRemoveFromParent() override;
3636
void OnUpdateSubtreeProperties(
3737
const DisplayList& subtree_properties) override;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PlatformRendererDarwin : public PlatformRendererImpl {
4444
void OnUpdateDisplayList(DisplayList display_list) override;
4545
void OnUpdateAttributes(const fml::RefPtr<PropBundle>& attributes,
4646
bool tends_to_flatten) override;
47-
void OnAddChild(PlatformRenderer* child) override;
47+
void OnAddChild(PlatformRenderer* child, int index) override;
4848
void OnRemoveFromParent() override;
4949
void OnUpdateSubtreeProperties(const DisplayList& subtree_properties) override;
5050
void UpdatePlatformExtraBundle(id platform_extra_bundle);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ bool ShouldDetachThroughUIOwner(LynxUIOwner* owner, int sign) {
147147
}
148148
}
149149

150-
void PlatformRendererDarwin::OnAddChild(PlatformRenderer* child) {
150+
void PlatformRendererDarwin::OnAddChild(PlatformRenderer* child, int /* index */) {
151+
// TODO(linxs): Support indexed insertion on iOS after mapping the
152+
// platform renderer child index to the corresponding UIOwner/UIView child index.
151153
if (child == nullptr) {
152154
return;
153155
}

core/renderer/ui_wrapper/painting/native_painting_context_platform_ref.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void NativePaintingCtxPlatformRef::RebuildSubLayers(
135135
int child_id = new_children[insert_pos];
136136
auto child_it = renderers_.find(child_id);
137137
if (child_it != renderers_.end()) {
138-
renderer->AddChild(child_it->second);
138+
renderer->AddChild(child_it->second, insert_pos);
139139
}
140140
}
141141
}

core/renderer/ui_wrapper/painting/platform_renderer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class PlatformRenderer : public fml::RefCountedThreadSafeStorage {
3131
virtual void UpdateAttributes(const fml::RefPtr<PropBundle>& attributes,
3232
bool tends_to_flatten) = 0;
3333
// Add a child renderer
34-
virtual void AddChild(fml::RefPtr<PlatformRenderer> child) = 0;
34+
virtual void AddChild(fml::RefPtr<PlatformRenderer> child,
35+
int index = -1) = 0;
3536

3637
// Remove this renderer from its parent
3738
virtual void RemoveFromParent() = 0;

core/renderer/ui_wrapper/painting/platform_renderer_impl.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void PlatformRendererImpl::UpdateAttributes(
5353
OnUpdateAttributes(attributes, tends_to_flatten);
5454
}
5555

56-
void PlatformRendererImpl::AddChild(fml::RefPtr<PlatformRenderer> child) {
56+
void PlatformRendererImpl::AddChild(fml::RefPtr<PlatformRenderer> child,
57+
int index) {
5758
if (!child) {
5859
return;
5960
}
@@ -64,14 +65,22 @@ void PlatformRendererImpl::AddChild(fml::RefPtr<PlatformRenderer> child) {
6465
child_impl->RemoveFromParent();
6566
}
6667

68+
const bool should_append =
69+
index < 0 || static_cast<size_t>(index) >= children_.size();
70+
const int insert_index = should_append ? -1 : index;
71+
6772
// Set parent relationship
6873
child_impl->parent_ = this;
6974

7075
// Call platform-specific implementation
71-
OnAddChild(child.get());
76+
OnAddChild(child.get(), insert_index);
7277

7378
// Add to children list
74-
children_.push_back(std::move(child));
79+
if (should_append) {
80+
children_.push_back(std::move(child));
81+
} else {
82+
children_.insert(children_.begin() + index, std::move(child));
83+
}
7584
}
7685

7786
void PlatformRendererImpl::RemoveFromParent() {

core/renderer/ui_wrapper/painting/platform_renderer_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PlatformRendererImpl : public PlatformRenderer {
4343
const DisplayList& GetDisplayList() const { return display_list_; }
4444

4545
void RemoveFromParent() override;
46-
void AddChild(fml::RefPtr<PlatformRenderer> child) override;
46+
void AddChild(fml::RefPtr<PlatformRenderer> child, int index = -1) override;
4747

4848
const ChildVecT& Children() const override { return children_; }
4949

@@ -68,7 +68,7 @@ class PlatformRendererImpl : public PlatformRenderer {
6868
virtual void OnUpdateDisplayList(DisplayList display_list) = 0;
6969
virtual void OnUpdateAttributes(const fml::RefPtr<PropBundle>& attributes,
7070
bool tends_to_flatten) = 0;
71-
virtual void OnAddChild(PlatformRenderer* child) = 0;
71+
virtual void OnAddChild(PlatformRenderer* child, int index) = 0;
7272
virtual void OnRemoveFromParent() = 0;
7373
virtual void OnUpdateSubtreeProperties(
7474
const DisplayList& subtree_properties) = 0;

platform/android/lynx_android/src/main/java/com/lynx/tasm/behavior/render/Renderer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public void setUIHost(LynxBaseUI uiHost) {
9797
}
9898

9999
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
100+
// TODO(linxs): Rename this to performMeasureChildren and remove the unused measure
101+
// spec parameters, since this method only measures renderer host children.
100102
if (mRenderHost == null) {
101103
return;
102104
}
@@ -120,6 +122,8 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
120122
}
121123

122124
public void onLayout(boolean changed, int l, int t, int r, int b) {
125+
// TODO(linxs): Rename this to performLayoutChildren, since this method only lays out
126+
// renderer host children.
123127
if (mRenderHost == null) {
124128
return;
125129
}

0 commit comments

Comments
 (0)