Unverified Commit 21cfed34 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

(insert|move|remove)ChildRenderObject Deprecation: Step 1 (#64189)

* (insert|move|remove)ChildRenderObject Deprecation: Step 1

This deprecates the following methods:

* RenderObjectElement.insertChildRenderObject
* RenderObjectElement.moveChildRenderObject
* RenderObjectElement.removeChildRenderObject

...and replaces them with the following methods:

* RenderObjectElement.insertRenderObjectChild
* RenderObjectElement.moveRenderObjectChild
* RenderObjectElement.removeRenderObjectChild

The reason for the deprecation is to provide the `oldSlot` argument to
the `moveRenderObjectChild` method (such an argument was missing from
the now-deprecated `moveChildRenderObject` method) and the `slot`
argument to the `removeRenderObjectChild` method (such an argument was
missing from the now-deprecated `removeChildRenderObject` method). While
no argument was added to `insertRenderObjectChild`, the name change (and
corresponding deprecation) was made to maintain naming parity with the
other two methods.

This initial step does not update or remove any of the `slotToChild`
patterns that exist in the framework. This work is being separated
into two commits in case something needs to be reverted to minimize
the scope of each commit.

See https://github.com/flutter/flutter/issues/63269 for more info
parent 04f7c9d5
...@@ -448,13 +448,13 @@ class _CupertinoAlertRenderElement extends RenderObjectElement { ...@@ -448,13 +448,13 @@ class _CupertinoAlertRenderElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, _AlertSections slot) { void insertRenderObjectChild(RenderObject child, _AlertSections slot) {
_placeChildInSlot(child, slot); _placeChildInSlot(child, slot);
} }
@override @override
void moveChildRenderObject(RenderObject child, _AlertSections slot) { void moveRenderObjectChild(RenderObject child, _AlertSections oldSlot, _AlertSections newSlot) {
_placeChildInSlot(child, slot); _placeChildInSlot(child, newSlot);
} }
@override @override
...@@ -478,7 +478,7 @@ class _CupertinoAlertRenderElement extends RenderObjectElement { ...@@ -478,7 +478,7 @@ class _CupertinoAlertRenderElement extends RenderObjectElement {
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, _AlertSections slot) {
assert(child == renderObject.contentSection || child == renderObject.actionsSection); assert(child == renderObject.contentSection || child == renderObject.actionsSection);
if (renderObject.contentSection == child) { if (renderObject.contentSection == child) {
renderObject.contentSection = null; renderObject.contentSection = null;
......
...@@ -433,7 +433,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement { ...@@ -433,7 +433,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, _AlertDialogSections slot) { void insertRenderObjectChild(RenderObject child, _AlertDialogSections slot) {
assert(slot != null); assert(slot != null);
switch (slot) { switch (slot) {
case _AlertDialogSections.contentSection: case _AlertDialogSections.contentSection:
...@@ -446,7 +446,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement { ...@@ -446,7 +446,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
} }
@override @override
void moveChildRenderObject(RenderObject child, _AlertDialogSections slot) { void moveRenderObjectChild(RenderObject child, _AlertDialogSections oldSlot, _AlertDialogSections newSlot) {
assert(false); assert(false);
} }
...@@ -470,7 +470,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement { ...@@ -470,7 +470,7 @@ class _CupertinoDialogRenderElement extends RenderObjectElement {
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, _AlertDialogSections slot) {
assert(child == renderObject.contentSection || child == renderObject.actionsSection); assert(child == renderObject.contentSection || child == renderObject.actionsSection);
if (renderObject.contentSection == child) { if (renderObject.contentSection == child) {
renderObject.contentSection = null; renderObject.contentSection = null;
......
...@@ -775,10 +775,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -775,10 +775,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, dynamic slot) { void insertRenderObjectChild(RenderObject child, dynamic slot) {
if (slot is _CupertinoTextSelectionToolbarItemsSlot) { if (slot is _CupertinoTextSelectionToolbarItemsSlot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(slot is _CupertinoTextSelectionToolbarItemsSlot);
_updateRenderObject(child as RenderBox, slot); _updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.containsKey(child)); assert(renderObject.childToSlot.containsKey(child));
assert(renderObject.slotToChild.containsKey(slot)); assert(renderObject.slotToChild.containsKey(slot));
...@@ -794,9 +793,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -794,9 +793,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
// This is not reachable for children that don't have an IndexedSlot. // This is not reachable for children that don't have an IndexedSlot.
@override @override
void moveChildRenderObject(RenderObject child, IndexedSlot<Element> slot) { void moveRenderObjectChild(RenderObject child, IndexedSlot<Element> oldSlot, IndexedSlot<Element> newSlot) {
assert(child.parent == renderObject); assert(child.parent == renderObject);
renderObject.move(child as RenderBox, after: slot?.value?.renderObject as RenderBox); renderObject.move(child as RenderBox, after: newSlot?.value?.renderObject as RenderBox);
} }
static bool _shouldPaint(Element child) { static bool _shouldPaint(Element child) {
...@@ -804,18 +803,20 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -804,18 +803,20 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, dynamic slot) {
// Check if the child is in a slot. // Check if the child is in a slot.
if (renderObject.childToSlot.containsKey(child)) { if (slot is _CupertinoTextSelectionToolbarItemsSlot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(renderObject.slotToChild.containsKey(slot));
assert(renderObject.childToSlot.containsKey(child)); assert(renderObject.childToSlot.containsKey(child));
_updateRenderObject(null, renderObject.childToSlot[child]); _updateRenderObject(null, slot);
assert(!renderObject.childToSlot.containsKey(child)); assert(!renderObject.childToSlot.containsKey(child));
assert(!renderObject.slotToChild.containsKey(slot)); assert(!renderObject.slotToChild.containsKey(slot));
return; return;
} }
// Otherwise look for it in the list of children. // Otherwise look for it in the list of children.
assert(slot is IndexedSlot);
assert(child.parent == renderObject); assert(child.parent == renderObject);
renderObject.remove(child as RenderBox); renderObject.remove(child as RenderBox);
} }
......
...@@ -2148,26 +2148,25 @@ class _RenderChipElement extends RenderObjectElement { ...@@ -2148,26 +2148,25 @@ class _RenderChipElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, dynamic slotValue) { void insertRenderObjectChild(RenderObject child, _ChipSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(slotValue is _ChipSlot);
final _ChipSlot slot = slotValue as _ChipSlot;
_updateRenderObject(child, slot); _updateRenderObject(child, slot);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot)); assert(renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, _ChipSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot[child] == slot);
_updateRenderObject(null, renderObject.childToSlot[child]); assert(renderObject.slotToChild[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child)); assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot)); assert(!renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slotValue) { void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false, 'not reachable'); assert(false, 'not reachable');
} }
} }
......
...@@ -1654,26 +1654,25 @@ class _RenderDecorationElement extends RenderObjectElement { ...@@ -1654,26 +1654,25 @@ class _RenderDecorationElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, dynamic slotValue) { void insertRenderObjectChild(RenderObject child, _DecorationSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(slotValue is _DecorationSlot);
final _DecorationSlot slot = slotValue as _DecorationSlot;
_updateRenderObject(child as RenderBox, slot); _updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot)); assert(renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, _DecorationSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot[child] == slot);
_updateRenderObject(null, renderObject.childToSlot[child]); assert(renderObject.slotToChild[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child)); assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot)); assert(!renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slotValue) { void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false, 'not reachable'); assert(false, 'not reachable');
} }
} }
......
...@@ -1250,26 +1250,25 @@ class _ListTileElement extends RenderObjectElement { ...@@ -1250,26 +1250,25 @@ class _ListTileElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, dynamic slotValue) { void insertRenderObjectChild(RenderObject child, _ListTileSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(slotValue is _ListTileSlot);
final _ListTileSlot slot = slotValue as _ListTileSlot;
_updateRenderObject(child as RenderBox, slot); _updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot)); assert(renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, _ListTileSlot slot) {
assert(child is RenderBox); assert(child is RenderBox);
assert(renderObject.childToSlot.keys.contains(child)); assert(renderObject.childToSlot[child] == slot);
_updateRenderObject(null, renderObject.childToSlot[child]); assert(renderObject.slotToChild[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child)); assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot)); assert(!renderObject.slotToChild.keys.contains(slot));
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slotValue) { void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false, 'not reachable'); assert(false, 'not reachable');
} }
} }
......
...@@ -1268,19 +1268,19 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RootRenderObje ...@@ -1268,19 +1268,19 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RootRenderObje
RenderObjectWithChildMixin<T> get renderObject => super.renderObject as RenderObjectWithChildMixin<T>; RenderObjectWithChildMixin<T> get renderObject => super.renderObject as RenderObjectWithChildMixin<T>;
@override @override
void insertChildRenderObject(RenderObject child, dynamic slot) { void insertRenderObjectChild(RenderObject child, dynamic slot) {
assert(slot == _rootChildSlot); assert(slot == _rootChildSlot);
assert(renderObject.debugValidateChild(child)); assert(renderObject.debugValidateChild(child));
renderObject.child = child as T; renderObject.child = child as T;
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slot) { void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false); assert(false);
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, dynamic slot) {
assert(renderObject.child == child); assert(renderObject.child == child);
renderObject.child = null; renderObject.child = null;
} }
......
...@@ -156,7 +156,7 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb ...@@ -156,7 +156,7 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb
} }
@override @override
void insertChildRenderObject(RenderObject child, dynamic slot) { void insertRenderObjectChild(RenderObject child, dynamic slot) {
final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject; final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject;
assert(slot == null); assert(slot == null);
assert(renderObject.debugValidateChild(child)); assert(renderObject.debugValidateChild(child));
...@@ -165,12 +165,12 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb ...@@ -165,12 +165,12 @@ class _LayoutBuilderElement<ConstraintType extends Constraints> extends RenderOb
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slot) { void moveRenderObjectChild(RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false); assert(false);
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, dynamic slot) {
final RenderConstrainedLayoutBuilder<ConstraintType, RenderObject> renderObject = this.renderObject; final RenderConstrainedLayoutBuilder<ConstraintType, RenderObject> renderObject = this.renderObject;
assert(renderObject.child == child); assert(renderObject.child == child);
renderObject.child = null; renderObject.child = null;
......
...@@ -907,7 +907,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana ...@@ -907,7 +907,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
} }
@override @override
void insertChildRenderObject(RenderObject child, int slot) { void insertRenderObjectChild(RenderObject child, int slot) {
final RenderListWheelViewport renderObject = this.renderObject; final RenderListWheelViewport renderObject = this.renderObject;
assert(renderObject.debugValidateChild(child)); assert(renderObject.debugValidateChild(child));
renderObject.insert(child as RenderBox, after: _childElements[slot - 1]?.renderObject as RenderBox); renderObject.insert(child as RenderBox, after: _childElements[slot - 1]?.renderObject as RenderBox);
...@@ -915,7 +915,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana ...@@ -915,7 +915,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slot) { void moveRenderObjectChild(RenderObject child, int oldSlot, int newSlot) {
const String moveChildRenderObjectErrorMessage = const String moveChildRenderObjectErrorMessage =
'Currently we maintain the list in contiguous increasing order, so ' 'Currently we maintain the list in contiguous increasing order, so '
'moving children around is not allowed.'; 'moving children around is not allowed.';
...@@ -923,7 +923,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana ...@@ -923,7 +923,7 @@ class ListWheelElement extends RenderObjectElement implements ListWheelChildMana
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, int slot) {
assert(child.parent == renderObject); assert(child.parent == renderObject);
renderObject.remove(child as RenderBox); renderObject.remove(child as RenderBox);
} }
......
...@@ -1273,7 +1273,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render ...@@ -1273,7 +1273,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
} }
@override @override
void insertChildRenderObject(covariant RenderObject child, int slot) { void insertRenderObjectChild(covariant RenderObject child, int slot) {
assert(slot != null); assert(slot != null);
assert(_currentlyUpdatingChildIndex == slot); assert(_currentlyUpdatingChildIndex == slot);
assert(renderObject.debugValidateChild(child)); assert(renderObject.debugValidateChild(child));
...@@ -1286,14 +1286,14 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render ...@@ -1286,14 +1286,14 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement implements Render
} }
@override @override
void moveChildRenderObject(covariant RenderObject child, int slot) { void moveRenderObjectChild(covariant RenderObject child, int oldSlot, int newSlot) {
assert(slot != null); assert(newSlot != null);
assert(_currentlyUpdatingChildIndex == slot); assert(_currentlyUpdatingChildIndex == newSlot);
renderObject.move(child as RenderBox, after: _currentBeforeChild); renderObject.move(child as RenderBox, after: _currentBeforeChild);
} }
@override @override
void removeChildRenderObject(covariant RenderObject child) { void removeRenderObjectChild(covariant RenderObject child, int slot) {
assert(_currentlyUpdatingChildIndex != null); assert(_currentlyUpdatingChildIndex != null);
renderObject.remove(child as RenderBox); renderObject.remove(child as RenderBox);
} }
......
...@@ -236,18 +236,18 @@ class _SliverPersistentHeaderElement extends RenderObjectElement { ...@@ -236,18 +236,18 @@ class _SliverPersistentHeaderElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(covariant RenderBox child, dynamic slot) { void insertRenderObjectChild(covariant RenderBox child, dynamic slot) {
assert(renderObject.debugValidateChild(child)); assert(renderObject.debugValidateChild(child));
renderObject.child = child; renderObject.child = child;
} }
@override @override
void moveChildRenderObject(covariant RenderObject child, dynamic slot) { void moveRenderObjectChild(covariant RenderObject child, dynamic oldSlot, dynamic newSlot) {
assert(false); assert(false);
} }
@override @override
void removeChildRenderObject(covariant RenderObject child) { void removeRenderObjectChild(covariant RenderObject child, dynamic slot) {
renderObject.child = null; renderObject.child = null;
} }
......
...@@ -75,12 +75,12 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement { ...@@ -75,12 +75,12 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement {
static final Object _prototypeSlot = Object(); static final Object _prototypeSlot = Object();
@override @override
void insertChildRenderObject(covariant RenderObject child, covariant dynamic slot) { void insertRenderObjectChild(covariant RenderObject child, covariant dynamic slot) {
if (slot == _prototypeSlot) { if (slot == _prototypeSlot) {
assert(child is RenderBox); assert(child is RenderBox);
renderObject.child = child as RenderBox; renderObject.child = child as RenderBox;
} else { } else {
super.insertChildRenderObject(child, slot as int); super.insertRenderObjectChild(child, slot as int);
} }
} }
...@@ -91,19 +91,19 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement { ...@@ -91,19 +91,19 @@ class _SliverPrototypeExtentListElement extends SliverMultiBoxAdaptorElement {
} }
@override @override
void moveChildRenderObject(RenderBox child, dynamic slot) { void moveRenderObjectChild(RenderBox child, dynamic oldSlot, dynamic newSlot) {
if (slot == _prototypeSlot) if (newSlot == _prototypeSlot)
assert(false); // There's only one prototype child so it cannot be moved. assert(false); // There's only one prototype child so it cannot be moved.
else else
super.moveChildRenderObject(child, slot as int); super.moveRenderObjectChild(child, oldSlot as int, newSlot as int);
} }
@override @override
void removeChildRenderObject(RenderBox child) { void removeRenderObjectChild(RenderBox child, dynamic slot) {
if (renderObject.child == child) if (renderObject.child == child)
renderObject.child = null; renderObject.child = null;
else else
super.removeChildRenderObject(child); super.removeRenderObjectChild(child, slot as int);
} }
@override @override
......
...@@ -303,16 +303,16 @@ class _TableElement extends RenderObjectElement { ...@@ -303,16 +303,16 @@ class _TableElement extends RenderObjectElement {
} }
@override @override
void insertChildRenderObject(RenderObject child, IndexedSlot<Element> slot) { void insertRenderObjectChild(RenderObject child, IndexedSlot<Element> slot) {
renderObject.setupParentData(child); renderObject.setupParentData(child);
} }
@override @override
void moveChildRenderObject(RenderObject child, dynamic slot) { void moveRenderObjectChild(RenderObject child, IndexedSlot<Element> oldSlot, IndexedSlot<Element> newSlot) {
} }
@override @override
void removeChildRenderObject(RenderObject child) { void removeRenderObjectChild(RenderObject child, IndexedSlot<Element> slot) {
final TableCellParentData childParentData = child.parentData as TableCellParentData; final TableCellParentData childParentData = child.parentData as TableCellParentData;
renderObject.setChild(childParentData.x, childParentData.y, null); renderObject.setChild(childParentData.x, childParentData.y, null);
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment