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) {
|
||||
//Found swap idx,position
|
||||
ViewNode<?> reused = mChildNodes.remove(position);
|
||||
ViewNode<?> abandoned = mChildNodes.remove(idx);
|
||||
ViewNode<?> reused = mChildNodes.get(position);
|
||||
mChildNodes.set(idx, reused);
|
||||
mChildNodes.set(position, abandoned);
|
||||
mChildNodes.set(position, oldNode);
|
||||
//View swap index
|
||||
mView.removeView(reused.getNodeView());
|
||||
mView.addView(reused.getNodeView(), Math.min(idx, mView.getChildCount()));
|
||||
mView.removeView(abandoned.getNodeView());
|
||||
mView.addView(abandoned.getNodeView(), position);
|
||||
mView.removeView(oldNode.getNodeView());
|
||||
mView.addView(oldNode.getNodeView(), position);
|
||||
} else {
|
||||
//Not found,insert
|
||||
ViewNode<?> newNode = ViewNode.create(getDoricContext(), type);
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
layoutConfig,
|
||||
modal,
|
||||
Panel,
|
||||
View,
|
||||
} from "doric";
|
||||
|
||||
interface CountModel {
|
||||
@ -25,13 +26,29 @@ class CounterView extends ViewHolder {
|
||||
number!: Text;
|
||||
counter!: Text;
|
||||
build(root: Group) {
|
||||
vlayout(
|
||||
let group = vlayout(
|
||||
[
|
||||
text({
|
||||
text: `Current language is ${Environment.localeLanguage}`,
|
||||
onClick: function () {
|
||||
const v = this as View
|
||||
group.removeChild(v)
|
||||
}
|
||||
}),
|
||||
text({
|
||||
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({
|
||||
textSize: 40,
|
||||
|
@ -97,18 +97,8 @@ - (void)configChildNodes {
|
||||
if (position >= 0) {
|
||||
///Found ,swap idx,position
|
||||
DoricViewNode *reused = childNodes[(NSUInteger) position];
|
||||
[childNodes removeObjectAtIndex:(NSUInteger) position];
|
||||
[childNodes removeObjectAtIndex:idx];
|
||||
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];
|
||||
}
|
||||
childNodes[idx] = reused;
|
||||
childNodes[(NSUInteger) position] = oldNode;
|
||||
///View swap index
|
||||
[reused.view removeFromSuperview];
|
||||
[oldNode.view removeFromSuperview];
|
||||
|
Reference in New Issue
Block a user