fix when remove child node from group node,reuse cause problem
This commit is contained in:
parent
53452e1d53
commit
3250523fb4
@ -108,15 +108,14 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
|||||||
}
|
}
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
//Found swap idx,position
|
//Found swap idx,position
|
||||||
ViewNode<?> reused = mChildNodes.remove(position);
|
ViewNode<?> reused = mChildNodes.get(position);
|
||||||
ViewNode<?> abandoned = mChildNodes.remove(idx);
|
|
||||||
mChildNodes.set(idx, reused);
|
mChildNodes.set(idx, reused);
|
||||||
mChildNodes.set(position, abandoned);
|
mChildNodes.set(position, oldNode);
|
||||||
//View swap index
|
//View swap index
|
||||||
mView.removeView(reused.getNodeView());
|
mView.removeView(reused.getNodeView());
|
||||||
mView.addView(reused.getNodeView(), Math.min(idx, mView.getChildCount()));
|
mView.addView(reused.getNodeView(), Math.min(idx, mView.getChildCount()));
|
||||||
mView.removeView(abandoned.getNodeView());
|
mView.removeView(oldNode.getNodeView());
|
||||||
mView.addView(abandoned.getNodeView(), position);
|
mView.addView(oldNode.getNodeView(), position);
|
||||||
} else {
|
} else {
|
||||||
//Not found,insert
|
//Not found,insert
|
||||||
ViewNode<?> newNode = ViewNode.create(getDoricContext(), type);
|
ViewNode<?> newNode = ViewNode.create(getDoricContext(), type);
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
layoutConfig,
|
layoutConfig,
|
||||||
modal,
|
modal,
|
||||||
Panel,
|
Panel,
|
||||||
|
View,
|
||||||
} from "doric";
|
} from "doric";
|
||||||
|
|
||||||
interface CountModel {
|
interface CountModel {
|
||||||
@ -25,13 +26,29 @@ class CounterView extends ViewHolder {
|
|||||||
number!: Text;
|
number!: Text;
|
||||||
counter!: Text;
|
counter!: Text;
|
||||||
build(root: Group) {
|
build(root: Group) {
|
||||||
vlayout(
|
let group = vlayout(
|
||||||
[
|
[
|
||||||
text({
|
text({
|
||||||
text: `Current language is ${Environment.localeLanguage}`,
|
text: `Current language is ${Environment.localeLanguage}`,
|
||||||
|
onClick: function () {
|
||||||
|
const v = this as View
|
||||||
|
group.removeChild(v)
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
text({
|
text({
|
||||||
text: `Current country is ${Environment.localeCountry}`,
|
text: `Current country is ${Environment.localeCountry}`,
|
||||||
|
onClick: function () {
|
||||||
|
const v = this as View
|
||||||
|
group.removeChild(v)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "Click to remove",
|
||||||
|
textSize: 30,
|
||||||
|
onClick: function () {
|
||||||
|
const v = this as View
|
||||||
|
group.removeChild(v)
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
this.number = text({
|
this.number = text({
|
||||||
textSize: 40,
|
textSize: 40,
|
||||||
|
@ -97,18 +97,8 @@ - (void)configChildNodes {
|
|||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
///Found ,swap idx,position
|
///Found ,swap idx,position
|
||||||
DoricViewNode *reused = childNodes[(NSUInteger) position];
|
DoricViewNode *reused = childNodes[(NSUInteger) position];
|
||||||
[childNodes removeObjectAtIndex:(NSUInteger) position];
|
childNodes[idx] = reused;
|
||||||
[childNodes removeObjectAtIndex:idx];
|
childNodes[(NSUInteger) position] = oldNode;
|
||||||
if (idx >= childNodes.count) {
|
|
||||||
[childNodes addObject:reused];
|
|
||||||
} else {
|
|
||||||
[childNodes insertObject:reused atIndex:idx];
|
|
||||||
}
|
|
||||||
if (position >= childNodes.count) {
|
|
||||||
[childNodes addObject:oldNode];
|
|
||||||
} else {
|
|
||||||
[childNodes insertObject:oldNode atIndex:(NSUInteger) position];
|
|
||||||
}
|
|
||||||
///View swap index
|
///View swap index
|
||||||
[reused.view removeFromSuperview];
|
[reused.view removeFromSuperview];
|
||||||
[oldNode.view removeFromSuperview];
|
[oldNode.view removeFromSuperview];
|
||||||
|
Reference in New Issue
Block a user