Skip to content

Commit f2ee1e2

Browse files
bodymovinbodymovin
andcommitted
runtime list updates (#9855) f660dea549
* runtime list updates Co-authored-by: hernan <hernan@rive.app>
1 parent 6d3f233 commit f2ee1e2

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

.rive_head

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b8bfaaf5e7d1b859c7be04d7139aeaea3eb474a1
1+
f660dea5494097df60419b00af6baf1c1e1b896d

js/src/rive.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3281,9 +3281,14 @@ export class ViewModelInstance {
32813281
}
32823282

32833283
public addParent(parent: ViewModelInstance) {
3284-
this._parents.push(parent);
3285-
if (this._propertiesWithCallbacks.length > 0 || this._children.length > 0) {
3286-
parent.addToViewModelCallbacks(this);
3284+
if (!this._parents.includes(parent)) {
3285+
this._parents.push(parent);
3286+
if (
3287+
this._propertiesWithCallbacks.length > 0 ||
3288+
this._children.length > 0
3289+
) {
3290+
parent.addToViewModelCallbacks(this);
3291+
}
32873292
}
32883293
}
32893294

@@ -3905,6 +3910,7 @@ export class ViewModelInstanceList extends ViewModelInstanceValue {
39053910
(this._viewModelInstanceValue as rc.ViewModelInstanceList).addInstance(
39063911
instance.runtimeInstance!,
39073912
);
3913+
instance.addParent(this._parentViewModel);
39083914
}
39093915
}
39103916

@@ -3913,6 +3919,7 @@ export class ViewModelInstanceList extends ViewModelInstanceValue {
39133919
(this._viewModelInstanceValue as rc.ViewModelInstanceList).removeInstance(
39143920
instance.runtimeInstance!,
39153921
);
3922+
instance.removeParent(this._parentViewModel);
39163923
}
39173924
}
39183925

@@ -3927,12 +3934,19 @@ export class ViewModelInstanceList extends ViewModelInstanceValue {
39273934
this._viewModelInstanceValue as rc.ViewModelInstanceList
39283935
).instanceAt(index);
39293936
if (runtimeInstance != null) {
3930-
const viewModelInstance = new ViewModelInstance(runtimeInstance, null);
3937+
const viewModelInstance = new ViewModelInstance(
3938+
runtimeInstance,
3939+
this._parentViewModel,
3940+
);
39313941
return viewModelInstance;
39323942
}
39333943
return null;
39343944
}
39353945

3946+
public swap(a: number, b: number) {
3947+
(this._viewModelInstanceValue as rc.ViewModelInstanceList).swap(a, b);
3948+
}
3949+
39363950
public internalHandleCallback(callback: Function) {
39373951
callback();
39383952
}

js/src/rive_advanced.mjs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,7 @@ export declare class ViewModelInstanceList extends ViewModelInstanceValue {
928928
removeInstance(vmi: ViewModelInstance): void;
929929
removeInstanceAt(index: number): void;
930930
instanceAt(index: number): ViewModelInstance;
931+
swap(a: number, b: number): ViewModelInstance;
931932
}
932933
export declare class ViewModelInstanceAssetImage extends ViewModelInstanceValue {
933934
value(image: ImageInternal):void;

wasm/src/bindings.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,13 @@ EMSCRIPTEN_BINDINGS(RiveWASM)
12061206
optional_override([](rive::ViewModelInstanceListRuntime& self, int index) {
12071207
self.removeInstanceAt(index);
12081208
}),
1209-
allow_raw_pointers());
1209+
allow_raw_pointers())
1210+
.function(
1211+
"swap",
1212+
optional_override([](rive::ViewModelInstanceListRuntime& self, uint32_t a, uint32_t b) {
1213+
self.swap(a, b);
1214+
}),
1215+
allow_raw_pointers());
12101216
class_<rive::ViewModelInstanceAssetImageRuntime, base<rive::ViewModelInstanceValueRuntime>>(
12111217
"ViewModelInstanceAssetImage")
12121218
.function(

0 commit comments

Comments
 (0)