-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathRiveCommandQueue.h
More file actions
1140 lines (1049 loc) · 46.7 KB
/
Copy pathRiveCommandQueue.h
File metadata and controls
1140 lines (1049 loc) · 46.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// RiveCommandQueue.h
// RiveRuntime
//
// Created by David Skuza on 8/4/25.
// Copyright © 2025 Rive. All rights reserved.
//
#ifndef RiveCommandQueue_h
#define RiveCommandQueue_h
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <RiveRuntime/RiveEnums.h>
@protocol RiveCommandServerProtocol;
@protocol RiveFileListener;
@protocol RiveArtboardListener;
@protocol RiveViewModelInstanceListener;
@protocol RiveRenderImageListener;
@protocol RiveFontListener;
@protocol RiveAudioListener;
NS_ASSUME_NONNULL_BEGIN
/**
* @protocol RiveCommandQueueProtocol
*
* Defines the Objective-C interface for the Rive command queue, which provides
* a thread-safe mechanism for queuing and executing Rive operations.
*
* The command queue architecture separates command submission (on the main
* thread) from command processing (on a background thread via
* RiveCommandServer). This design allows the UI to remain responsive while Rive
* files are loaded, artboards are instantiated, and animations are advanced.
*
* All operations are asynchronous and use request IDs to correlate requests
* with responses delivered through listener protocols. Handles (uint64_t) are
* used to reference files, artboards, state machines, and other resources
* created through the queue.
*
* To use the command queue:
* 1. Create a RiveCommandQueue instance
* 2. Create a RiveCommandServer with the queue and start it on a background
* thread via serveUntilDisconnect.
* 3. Call start() to begin accepting commands
* 4. Submit commands using the protocol methods
* 5. Receive responses via listener protocol callbacks
* 6. Call disconnect() and stop() when done
*/
NS_SWIFT_NAME(CommandQueueProtocol)
@protocol RiveCommandQueueProtocol
/**
* Returns the next available request ID for correlating commands with
* responses.
*
* Request IDs are used to match asynchronous command submissions with their
* corresponding listener callbacks. Each call returns a unique ID that should
* be used for a single command operation.
*
* @return A unique request ID
*/
@property(nonatomic, readonly) uint64_t nextRequestID;
- (void)start;
- (void)stop;
#pragma mark - Server
/**
* Disconnects from the command server.
*/
- (void)disconnect;
#pragma mark - File
/**
* Loads a Rive file into the command queue.
*
* @param data The binary data of the Rive file to load
* @return A unique file handle identifier that can be used for subsequent
* operations
* @note The file handle is only valid for the lifetime of the loaded file.
* Once the file is deleted using deleteFile:, the handle becomes invalid.
*/
- (uint64_t)loadFile:(NSData*)data
observer:(id<RiveFileListener>)observer
requestID:(uint64_t)requestID;
/**
* Deletes a previously loaded Rive file.
*
* @param file The file handle of the file to delete
* @note This operation will also delete all artboards that were instantiated
* from this file.
*/
- (void)deleteFile:(uint64_t)file requestID:(uint64_t)requestID;
/**
* Requests artboard names for a loaded file.
*
* @param fileHandle The file handle of the file to query
* @param requestID The request ID for this operation
* @note The response will be delivered via the file listener observer's
* onArtboardsListed:requestID:names: method
*/
- (void)requestArtboardNames:(uint64_t)fileHandle requestID:(uint64_t)requestID;
/**
* Requests the names of all view models defined in a Rive file.
*
* @param fileHandle The file handle of the file to query
* @param requestID The request ID for this operation
* @note The response will be delivered via the file listener observer's
* onViewModelsListed:requestID:names: method
*/
- (void)requestViewModelNames:(uint64_t)fileHandle
requestID:(uint64_t)requestID;
/**
* Requests the enum definitions for all enums defined in a Rive file.
*
* @param fileHandle The file handle of the file to query
* @param requestID The request ID for this operation
* @note The response will be delivered via the file listener observer's
* onViewModelEnumsListed:requestID:enums: method
*/
- (void)requestViewModelEnums:(uint64_t)fileHandle
requestID:(uint64_t)requestID;
/**
* Requests the names of all view model instances for a specific view model.
*
* @param fileHandle The file handle of the file to query
* @param viewModelName The name of the view model to query
* @param requestID The request ID for this operation
* @note The response will be delivered via the file listener observer's
* onViewModelInstanceNamesListed:requestID:viewModelName:names: method
*/
- (void)requestViewModelInstanceNames:(uint64_t)fileHandle
viewModelName:(NSString*)viewModelName
requestID:(uint64_t)requestID;
/**
* Requests the property definitions for a specific view model.
*
* @param fileHandle The file handle of the file to query
* @param viewModelName The name of the view model to query
* @param requestID The request ID for this operation
* @note The response will be delivered via the file listener observer's
* onViewModelPropertiesListed:requestID:viewModelName:properties: method
*/
- (void)requestViewModelPropertyDefinitions:(uint64_t)fileHandle
viewModelName:(NSString*)viewModelName
requestID:(uint64_t)requestID;
/**
* Creates the default artboard for a file.
*
* @param fileHandle The file handle of the file
* @return The artboard handle of the created artboard
*/
- (uint64_t)createDefaultArtboardFromFile:(uint64_t)fileHandle
observer:(id<RiveArtboardListener>)observer
requestID:(uint64_t)requestID;
/**
* Creates an artboard with the specified name for a file.
*
* @param fileHandle The file handle of the file
* @param name The name of the artboard to create
* @return The artboard handle of the created artboard
*/
- (uint64_t)createArtboardNamed:(NSString*)name
fromFile:(uint64_t)fileHandle
observer:(id<RiveArtboardListener>)observer
requestID:(uint64_t)requestID;
/**
* Deletes a previously created artboard.
*
* This method removes an artboard via the command queue and frees all
* associated resources. After deletion, the artboard handle becomes invalid
* and should not be used for any further operations.
*
* @param artboard The artboard handle of the artboard to delete
* @note This operation is irreversible. Once an artboard is deleted, it
* cannot be recovered and all references to it become invalid.
*/
- (void)deleteArtboard:(uint64_t)artboard requestID:(uint64_t)requestID;
/**
* Sets the size of an artboard.
*
* This method sets the width and height of the specified artboard. The width
* and height are in display coordinates and will be divided by the scale factor
* to get the logical artboard size.
*
* @param artboardHandle The artboard handle of the artboard to resize
* @param width The width in display coordinates
* @param height The height in display coordinates
* @param scale The display scale factor (default: 1.0)
* @param requestID The request ID for this operation
*/
- (void)setArtboardSize:(uint64_t)artboardHandle
width:(float)width
height:(float)height
scale:(float)scale
requestID:(uint64_t)requestID;
/**
* Resets the artboard size to its original dimensions.
*
* This method restores the artboard to its original size as defined in the
* Rive file.
*
* @param artboardHandle The artboard handle of the artboard to reset
* @param requestID The request ID for this operation
*/
- (void)resetArtboardSize:(uint64_t)artboardHandle
requestID:(uint64_t)requestID;
/**
* Requests the names of all state machines available on an artboard.
*
* This method initiates an asynchronous request to retrieve the names of
* state machines that are available on the specified artboard. The response
* will be delivered via the artboard listener observer's
* onStateMachineNamesListed:names:requestID: method.
*
* @param artboardHandle The artboard handle of the artboard to query
* @param requestID The unique request ID for this operation
* @note The response will be delivered via the artboard listener observer's
* onStateMachineNamesListed:names:requestID: method. The request ID
* should be used to correlate the response with this request.
*/
- (void)requestStateMachineNames:(uint64_t)artboardHandle
requestID:(uint64_t)requestID;
/**
* Requests the default view model information for an artboard.
*
* This method initiates an asynchronous request to retrieve the default view
* model name and instance name for the specified artboard. The response will be
* delivered via the artboard listener observer's
* onDefaultViewModelInfoReceived:requestID:viewModelName:instanceName: method.
*
* @param artboardHandle The artboard handle of the artboard to query
* @param fileHandle The file handle of the file containing the artboard
* @param requestID The unique request ID for this operation
* @note The response will be delivered via the artboard listener observer's
* onDefaultViewModelInfoReceived:requestID:viewModelName:instanceName:
* method. The request ID should be used to correlate the response with this
* request.
*/
- (void)requestDefaultViewModelInfo:(uint64_t)artboardHandle
fromFile:(uint64_t)fileHandle
requestID:(uint64_t)requestID;
/**
* Creates the default state machine for an artboard.
*
* This method creates the default (first) state machine from the specified
* artboard. It delegates to the command queue and returns a handle that
* uniquely identifies the created state machine.
*
* @param artboardHandle The artboard handle of the artboard that owns the state
* machine
* @return The state machine handle of the created state machine
*/
- (uint64_t)createDefaultStateMachineFromArtboard:(uint64_t)artboardHandle
requestID:(uint64_t)requestID;
;
/**
* Creates a state machine with the specified name for an artboard.
*
* This method creates a state machine with the given name from the specified
* artboard. It delegates to the command queue and returns a handle that
* uniquely identifies the created state machine.
*
* @param name The name of the state machine to create
* @param artboardHandle The artboard handle of the artboard that owns the state
* machine
* @return The state machine handle of the created state machine
*/
- (uint64_t)createStateMachineNamed:(NSString*)name
fromArtboard:(uint64_t)artboardHandle
requestID:(uint64_t)requestID;
/**
* Advances a state machine by the specified time interval.
*
* @param stateMachineHandle The handle of the state machine to advance
* @param time The time interval in seconds to advance the state machine
* @param requestID The request ID for this operation
* @note This operation is typically called every frame. The time should
* represent the delta since the last advance call.
*/
- (void)advanceStateMachine:(uint64_t)stateMachineHandle
by:(NSTimeInterval)time
requestID:(uint64_t)requestID;
/**
* Deletes a previously created state machine.
*
* This method removes a state machine and frees all associated resources.
* After deletion, the state machine handle becomes invalid and should not
* be used for any further operations.
*
* @param stateMachineHandle The handle of the state machine to delete
* @param requestID The request ID for this operation
* @note This operation is irreversible. Once a state machine is deleted,
* it cannot be recovered.
*/
- (void)deleteStateMachine:(uint64_t)stateMachineHandle
requestID:(uint64_t)requestID;
/**
* Binds a view model instance to a state machine for data binding.
*
* @param stateMachineHandle The handle of the state machine to bind
* @param viewModelInstanceHandle The handle of the view model instance to bind
* @param requestID The request ID for this operation
* @note Only one view model instance can be bound to a state machine at a time.
* Binding a new instance will replace any previously bound instance.
*/
- (void)bindViewModelInstance:(uint64_t)stateMachineHandle
toViewModelInstance:(uint64_t)viewModelInstanceHandle
requestID:(uint64_t)requestID;
#pragma mark - Pointer Events
/**
* Sends a pointer move event to a state machine.
*
* @param stateMachineHandle The handle of the state machine to receive the
* event
* @param position The cursor position in screen coordinates
* @param screenBounds The bounds of the coordinate system of the cursor
* @param fit The fit the artboard is drawn with
* @param alignment The alignment the artboard is drawn with
* @param scaleFactor Scale factor for things like retina display (default: 1.0)
* @param requestID The request ID for this operation
*/
- (void)pointerMove:(uint64_t)stateMachineHandle
position:(CGPoint)position
screenBounds:(CGSize)screenBounds
fit:(RiveConfigurationFit)fit
alignment:(RiveConfigurationAlignment)alignment
scaleFactor:(float)scaleFactor
requestID:(uint64_t)requestID;
/**
* Sends a pointer down event to a state machine.
*
* @param stateMachineHandle The handle of the state machine to receive the
* event
* @param position The cursor position in screen coordinates
* @param screenBounds The bounds of the coordinate system of the cursor
* @param fit The fit the artboard is drawn with
* @param alignment The alignment the artboard is drawn with
* @param scaleFactor Scale factor for things like retina display (default: 1.0)
* @param requestID The request ID for this operation
*/
- (void)pointerDown:(uint64_t)stateMachineHandle
position:(CGPoint)position
screenBounds:(CGSize)screenBounds
fit:(RiveConfigurationFit)fit
alignment:(RiveConfigurationAlignment)alignment
scaleFactor:(float)scaleFactor
requestID:(uint64_t)requestID;
/**
* Sends a pointer up event to a state machine.
*
* @param stateMachineHandle The handle of the state machine to receive the
* event
* @param position The cursor position in screen coordinates
* @param screenBounds The bounds of the coordinate system of the cursor
* @param fit The fit the artboard is drawn with
* @param alignment The alignment the artboard is drawn with
* @param scaleFactor Scale factor for things like retina display (default: 1.0)
* @param requestID The request ID for this operation
*/
- (void)pointerUp:(uint64_t)stateMachineHandle
position:(CGPoint)position
screenBounds:(CGSize)screenBounds
fit:(RiveConfigurationFit)fit
alignment:(RiveConfigurationAlignment)alignment
scaleFactor:(float)scaleFactor
requestID:(uint64_t)requestID;
/**
* Sends a pointer exit event to a state machine.
*
* @param stateMachineHandle The handle of the state machine to receive the
* event
* @param position The cursor position in screen coordinates
* @param screenBounds The bounds of the coordinate system of the cursor
* @param fit The fit the artboard is drawn with
* @param alignment The alignment the artboard is drawn with
* @param scaleFactor Scale factor for things like retina display (default: 1.0)
* @param requestID The request ID for this operation
*/
- (void)pointerExit:(uint64_t)stateMachineHandle
position:(CGPoint)position
screenBounds:(CGSize)screenBounds
fit:(RiveConfigurationFit)fit
alignment:(RiveConfigurationAlignment)alignment
scaleFactor:(float)scaleFactor
requestID:(uint64_t)requestID;
#pragma mark - Drawing
/**
* Creates a unique draw key for coordinating drawing operations.
*
* @return A unique draw key identifier
* @note Draw keys should be created on the main thread and used immediately
* with draw:callback:. They are not meant to be stored or reused.
*/
- (uint64_t)createDrawKey;
/**
* Queues a drawing operation with a callback that receives the renderer.
*
* This method schedules a drawing operation that will be executed when the
* command server processes drawing commands. The callback receives a pointer
* to the C++ renderer object, which can be used to draw the artboard.
*
* The captured object parameter allows you to retain Objective-C objects that
* need to stay alive during the drawing operation. The finalize block is called
* after drawing completes and can be used to commit command buffers or perform
* cleanup.
*
* @param drawKey A unique draw key created with createDrawKey
* @param callback A block that receives the C++ renderer pointer (void*) and
* performs the actual drawing. This block is called on the
* background thread where the command server processes
* commands.
* @note The renderer pointer in the callback is only valid during the execution
* of the callback block. Do not store it for later use.
*/
- (void)draw:(uint64_t)drawKey callback:(void (^)(void*))callback;
#pragma mark - Data Binding
/**
* Creates a blank view model instance for an artboard's default view model.
*
* @param artboardHandle The artboard handle to get the default view model from
* @param fileHandle The file handle containing the artboard
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)
createBlankViewModelInstanceForArtboard:(uint64_t)artboardHandle
fromFile:(uint64_t)fileHandle
observer:(id<RiveViewModelInstanceListener>)
observer
requestID:(uint64_t)requestID;
/**
* Creates a blank view model instance for a named view model.
*
* @param viewModelName The name of the view model type to instantiate
* @param fileHandle The file handle containing the view model definition
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)createBlankViewModelInstanceNamed:(NSString*)viewModelName
fromFile:(uint64_t)fileHandle
observer:
(id<RiveViewModelInstanceListener>)
observer
requestID:(uint64_t)requestID;
/**
* Creates a view model instance with default values from an artboard.
*
* @param artboardHandle The artboard handle to get the default view model from
* @param fileHandle The file handle containing the artboard
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)
createDefaultViewModelInstanceForArtboard:(uint64_t)artboardHandle
fromFile:(uint64_t)fileHandle
observer:
(id<RiveViewModelInstanceListener>)
observer
requestID:(uint64_t)requestID;
/**
* Creates a view model instance with default values from a named view model.
*
* @param viewModelName The name of the view model type to instantiate
* @param fileHandle The file handle containing the view model definition
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)createDefaultViewModelInstanceNamed:(NSString*)viewModelName
fromFile:(uint64_t)fileHandle
observer:
(id<RiveViewModelInstanceListener>)
observer
requestID:(uint64_t)requestID;
/**
* Creates a view model instance by name from an artboard's view models.
*
* @param instanceName The name of the instance to create (as defined in the
* file)
* @param artboardHandle The artboard handle containing the instance definition
* @param fileHandle The file handle containing the artboard
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)createViewModelInstanceNamed:(NSString*)instanceName
forArtboard:(uint64_t)artboardHandle
fromFile:(uint64_t)fileHandle
observer:
(id<RiveViewModelInstanceListener>)observer
requestID:(uint64_t)requestID;
/**
* Creates a view model instance by name from a specific view model type.
*
* @param instanceName The name of the instance to create (as defined in the
* file)
* @param viewModelName The name of the view model type
* @param fileHandle The file handle containing the view model and instance
* @param observer The listener that will receive property updates
* @param requestID The request ID for this operation
* @return A view model instance handle (may be 0 if creation fails)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method
*/
- (uint64_t)createViewModelInstanceNamed:(NSString*)instanceName
viewModelName:(NSString*)viewModelName
fromFile:(uint64_t)fileHandle
observer:
(id<RiveViewModelInstanceListener>)observer
requestID:(uint64_t)requestID;
/**
* Requests the current string value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "title" or "user.name")
* @param requestID The request ID for correlating the response
* @note The property must be of type string. Use requestViewModelInstanceEnum:
* for enum properties that return string values.
*/
- (void)requestViewModelInstanceString:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the current number value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "score" or "position.x")
* @param requestID The request ID for correlating the response
* @note The property must be of type number or integer.
*/
- (void)requestViewModelInstanceNumber:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the current boolean value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "isEnabled" or "settings.autoSave")
* @param requestID The request ID for correlating the response
* @note The property must be of type boolean.
*/
- (void)requestViewModelInstanceBool:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the current color value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "backgroundColor")
* @param requestID The request ID for correlating the response
* @note The property must be of type color. The color is returned as a 32-bit
* ARGB integer where each component is 8 bits (A in bits 31-24,
* R in bits 23-16, G in bits 15-8, B in bits 7-0).
*/
- (void)requestViewModelInstanceColor:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the current enum value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "status" or "user.role")
* @param requestID The request ID for correlating the response
* @note The property must be of type enum. The enum value is returned as a
* string.
*/
- (void)requestViewModelInstanceEnum:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the size (element count) of a list property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path to the list (e.g., "items" or "users.friends")
* @param requestID The request ID for correlating the response
* @note The property must be of type list.
*/
- (void)requestViewModelInstanceListSize:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Requests the name of a view model instance.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param requestID The request ID for correlating the response
*/
- (void)requestViewModelInstanceName:(uint64_t)viewModelInstanceHandle
requestID:(uint64_t)requestID;
/**
* Sets the string value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "title" or "user.name")
* @param value The new string value
* @param requestID The request ID for this operation
* @note The property must be of type string. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceString:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(NSString*)value
requestID:(uint64_t)requestID;
/**
* Sets the number value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "score" or "position.x")
* @param value The new number value
* @param requestID The request ID for this operation
* @note The property must be of type number. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceNumber:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(float)value
requestID:(uint64_t)requestID;
/**
* Sets the boolean value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "isEnabled" or "settings.autoSave")
* @param value The new boolean value
* @param requestID The request ID for this operation
* @note The property must be of type boolean. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceBool:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(BOOL)value
requestID:(uint64_t)requestID;
/**
* Sets the color value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "backgroundColor")
* @param value The new color value as a 32-bit ARGB integer
* @param requestID The request ID for this operation
* @note The property must be of type color. The color should be a 32-bit ARGB
* integer where each component is 8 bits (A in bits 31-24, R in bits
* 23-16, G in bits 15-8, B in bits 7-0). Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceColor:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint32_t)value
requestID:(uint64_t)requestID;
/**
* Sets the enum value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "status" or "user.role")
* @param value The new enum value as a string
* @param requestID The request ID for this operation
* @note The property must be of type enum. The value must match one of the
* enum's defined values. Changes are applied asynchronously.
*/
- (void)setViewModelInstanceEnum:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(NSString*)value
requestID:(uint64_t)requestID;
/**
* Sets the image value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "avatar" or "user.profilePicture")
* @param value The handle of a decoded image
* @param requestID The request ID for this operation
* @note The property must be of type assetImage. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceImage:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
requestID:(uint64_t)requestID;
/**
* Sets the artboard value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "nestedArtboard")
* @param value The handle of a created artboard
* @param requestID The request ID for this operation
* @note The property must be of type artboard. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceArtboard:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
requestID:(uint64_t)requestID;
/**
* Sets a nested view model instance value of a view model property.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path (e.g., "user" or "settings.theme")
* @param value The handle of a created view model instance
* @param requestID The request ID for this operation
* @note The property must be of type viewModel. Changes are applied
* asynchronously.
*/
- (void)setViewModelInstanceNestedViewModel:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
requestID:(uint64_t)requestID;
/**
* Fires a trigger property in a view model instance.
*
* @param viewModelInstanceHandle The handle of the view model instance
* @param path The property path to the trigger (e.g., "buttonClicked")
* @param requestID The request ID for this operation
* @note The property must be of type trigger. Triggers are automatically reset
* after being fired.
*/
- (void)fireViewModelTrigger:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
requestID:(uint64_t)requestID;
/**
* Creates a reference to a nested view model instance property.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the nested view model (e.g., "user" or
* "settings.theme")
* @param observer The listener that will receive property updates for the
* nested instance
* @param requestID The request ID for this operation
* @return A view model instance handle for the nested instance (may be 0 if not
* found)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method. The handle remains
* valid as long as the parent instance exists.
*/
- (uint64_t)
referenceNestedViewModelInstance:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
observer:(id<RiveViewModelInstanceListener>)observer
requestID:(uint64_t)requestID;
/**
* Creates a reference to a view model instance in a list property.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items" or "users.friends")
* @param index The zero-based index of the element in the list
* @param observer The listener that will receive property updates for the
* element
* @param requestID The request ID for this operation
* @return A view model instance handle for the list element (may be 0 if index
* is invalid)
* @note The instance handle is delivered asynchronously via the observer's
* onViewModelDataReceived:requestID:data: method. The handle remains
* valid as long as the element exists in the list.
*/
- (uint64_t)
referenceListViewModelInstance:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
index:(int)index
observer:(id<RiveViewModelInstanceListener>)observer
requestID:(uint64_t)requestID;
/**
* Appends a view model instance to a list property.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items")
* @param value The handle of the view model instance to append
* @param requestID The request ID for this operation
* @note The property must be of type list. Changes are applied asynchronously.
*/
- (void)appendViewModelInstanceListViewModel:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
requestID:(uint64_t)requestID;
/**
* Inserts a view model instance into a list property at a specific index.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items")
* @param value The handle of the view model instance to insert
* @param index The zero-based index where to insert the element
* @param requestID The request ID for this operation
* @note The property must be of type list. The index must be between 0 and
* the current list size (inclusive). Changes are applied asynchronously.
*/
- (void)insertViewModelInstanceListViewModel:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
index:(int)index
requestID:(uint64_t)requestID;
/**
* Removes a view model instance from a list property by index.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items")
* @param index The zero-based index of the element to remove
* @param value The handle of the view model instance being removed (for
* validation)
* @param requestID The request ID for this operation
* @note The property must be of type list. Changes are applied asynchronously.
*/
- (void)removeViewModelInstanceListViewModelAtIndex:
(uint64_t)viewModelInstanceHandle
path:(NSString*)path
index:(int)index
value:(uint64_t)value
requestID:(uint64_t)requestID
NS_SWIFT_NAME(removeViewModelInstanceListViewModelAtIndex(_:path:index:value:requestID:));
/**
* Removes a view model instance from a list property by value.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items")
* @param value The handle of the view model instance to remove
* @param requestID The request ID for this operation
* @note The property must be of type list. Changes are applied asynchronously.
*/
- (void)removeViewModelInstanceListViewModelByValue:
(uint64_t)viewModelInstanceHandle
path:(NSString*)path
value:(uint64_t)value
requestID:(uint64_t)requestID
NS_SWIFT_NAME(removeViewModelInstanceListViewModelByValue(_:path:value:requestID:));
/**
* Swaps two elements in a list property by their indices.
*
* @param viewModelInstanceHandle The handle of the parent view model instance
* @param path The property path to the list (e.g., "items")
* @param atIndex The zero-based index of the first element
* @param withIndex The zero-based index of the second element
* @param requestID The request ID for this operation
* @note The property must be of type list. Changes are applied asynchronously.
*/
- (void)swapViewModelInstanceListValues:(uint64_t)viewModelInstanceHandle
path:(NSString*)path
atIndex:(int)atIndex
withIndex:(int)withIndex
requestID:(uint64_t)requestID
NS_SWIFT_NAME(swapViewModelInstanceListValues(_:path:atIndex:withIndex:requestID:));
/**
* Deletes a view model instance and frees its resources.
*
* @param viewModelInstance The handle of the view model instance to delete
* @param requestID The request ID for this operation
* @note This operation is irreversible. Make sure to unbind the instance from
* any state machines before deleting it.
*/
- (void)deleteViewModelInstance:(uint64_t)viewModelInstance
requestID:(uint64_t)requestID;
/**
* Subscribes to property change notifications for a view model property.
*
* @param viewModelInstance The handle of the view model instance
* @param path The property path to subscribe to (e.g., "title" or "user.name")
* @param type The expected data type of the property
* @param requestID The request ID for this operation
* @note You must provide the same observer that was used when creating the
* view model instance. Subscriptions remain active until you unsubscribe
* or the instance is deleted.
*/
- (void)subscribeToViewModelProperty:(uint64_t)viewModelInstance
path:(NSString*)path
type:(RiveViewModelInstanceDataType)type
requestID:(uint64_t)requestID;
/**
* Unsubscribes from property change notifications for a view model property.
*
* @param viewModelInstance The handle of the view model instance
* @param path The property path to unsubscribe from (e.g., "title")
* @param type The data type of the property (must match the subscription)
* @param requestID The request ID for this operation
* @note The type parameter must match the type used when subscribing.
*/
- (void)unsubscribeToViewModelProperty:(uint64_t)viewModelInstance
path:(NSString*)path
type:(RiveViewModelInstanceDataType)type
requestID:(uint64_t)requestID;
#pragma mark - RenderImage
/**
* Decodes image data and creates a render image resource.
*
* @param data The image data to decode
* @param listener The listener that will receive decode completion
* notifications
* @param requestID The request ID for correlating the response
* @return A temporary handle (the actual handle is delivered via the listener)
* @note The image handle is delivered via the listener's
* onRenderImageDecoded:requestID: method. If decoding fails,
* onRenderImageError:requestID:message: is called instead.
*/
- (uint64_t)decodeImage:(NSData*)data
listener:(id<RiveRenderImageListener>)listener
requestID:(uint64_t)requestID;
/**
* Deletes a previously decoded render image.
*
* This frees the image resources. After deletion, the image handle becomes
* invalid and should not be used for any further operations.
*
* @param renderImage The handle of the image to delete
* @param requestID The request ID for this operation
* @note This operation is irreversible. Make sure to remove the image from
* any global assets before deleting it.
*/
- (void)deleteImage:(uint64_t)renderImage requestID:(uint64_t)requestID;
/**
* Adds a decoded image as a global asset that can be referenced by name.
*
* @param name The asset name to use (must match the name in the Rive file)
* @param imageHandle The handle of the decoded image
* @param requestID The request ID for this operation
* @note If an asset with the same name already exists, it will be replaced.
*/
- (void)addGlobalImageAsset:(NSString*)name
imageHandle:(uint64_t)imageHandle
requestID:(uint64_t)requestID;
/**
* Removes a global image asset by name.
*
* After removal, the asset name will no longer resolve to the image. The
* image itself is not deleted; use deleteImage:requestID: to free the image
* resources if needed.
*
* @param name The asset name to remove