Skip to content

Commit

Permalink
fix: removed _recursiveBatchUpdates. Will be handled differently in t…
Browse files Browse the repository at this point in the history
…he future in N
  • Loading branch information
farfromrefug committed Jan 28, 2021
1 parent d907cd4 commit 9e15d48
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 50 deletions.
36 changes: 1 addition & 35 deletions src/collectionview-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,6 @@ export enum ContentInsetAdjustmentBehavior {
Never,
ScrollableAxes
}
declare module '@nativescript/core/ui/core/view-base' {
interface ViewBase {
_recursiveSuspendNativeUpdates(type);
_recursiveResumeNativeUpdates(type);
_recursiveBatchUpdates<T>(callback: () => T): T;
}
}

ViewBase.prototype._recursiveSuspendNativeUpdates = profile('_recursiveSuspendNativeUpdates', function (type) {
// we can suspendRequestLayout as it will be handled outside and after
this['suspendRequestLayout'] = true;
this._suspendNativeUpdates(type);
if (!(this instanceof CollectionViewBase)) {
this.eachChild((c) => c._recursiveSuspendNativeUpdates(type));
}
});
ViewBase.prototype._recursiveResumeNativeUpdates = profile('_recursiveResumeNativeUpdates', function (type) {
this._resumeNativeUpdates(type);
if (!(this instanceof CollectionViewBase)) {
this.eachChild((c) => c._recursiveResumeNativeUpdates(type));
}
this['suspendRequestLayout'] = false;
});

// right now _recursiveBatchUpdates suppose no view is added in the callback. If so it will crash from _resumeNativeUpdates
ViewBase.prototype._recursiveBatchUpdates = profile('_recursiveBatchUpdates', function <T>(callback: () => T): T {
try {
this._recursiveSuspendNativeUpdates(0);

return callback();
} finally {
this._recursiveResumeNativeUpdates(0);
}
});

export enum CLogTypes {
log = Trace.messageType.log,
Expand Down Expand Up @@ -105,7 +71,7 @@ export interface Plugin {
@CSSType('CollectionView')
export abstract class CollectionViewBase extends View implements CollectionViewDefinition {
public static itemLoadingEvent = 'itemLoading';
public static cellCreateEvent = 'cellCreate';
// public static cellCreateEvent = 'cellCreate';
public static scrollEvent = 'scroll';
public static scrollEndEvent = 'scrollEnd';
public static itemTapEvent = 'itemTap';
Expand Down
6 changes: 2 additions & 4 deletions src/svelte/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ export default class CollectionViewViewElement extends NativeViewElementNode<Col
// ensure we dont do unnecessary tasks if index did not change
// console.log('updateListItem', args.index, _view.__CollectionViewCurrentIndex__);
_view.__CollectionViewCurrentIndex__ = args.index;
_view._recursiveBatchUpdates(() => {
componentInstance.$set(props);
flush(); // we need to flush to make sure update is applied right away
});
componentInstance.$set(props);
flush(); // we need to flush to make sure update is applied right away
}
}

Expand Down
12 changes: 1 addition & 11 deletions src/vue/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,7 @@ export default {
const context = this.getItemContext(currentItem, index, isSelected);
const oldVnode = args.view && args.view[VUE_VIEW];

// TODO: patchTemplate is async in the sense it requires a next tick for
// the props to change :s
// this is an issue when you reuse a cell whene custom subviews measurement will change
if (args.view) {
// reusing
args.view._recursiveBatchUpdates(() => {
args.view = this.$templates.patchTemplate(name, context, oldVnode);
});
} else {
args.view = this.$templates.patchTemplate(name, context, oldVnode);
}
args.view = this.$templates.patchTemplate(name, context, oldVnode);
},
onItemLoadingInternal(args) {
this.updateViewTemplate(args);
Expand Down

0 comments on commit 9e15d48

Please sign in to comment.