-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcommon.ts
More file actions
239 lines (209 loc) · 6.25 KB
/
common.ts
File metadata and controls
239 lines (209 loc) · 6.25 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
import { Observable, Property, View, booleanConverter } from '@nativescript/core';
export enum TypeRiveLoop {
ONESHOT,
LOOP,
PINGPONG,
AUTO,
NONE,
}
export enum TypeRiveDirection {
BACKWARDS,
FORWARDS,
AUTO,
}
export enum TypeRiveFit {
FILL,
CONTAIN,
COVER,
FIT_WIDTH,
FIT_HEIGHT,
NONE,
SCALE_DOWN,
}
export enum TypeRiveAlignment {
TOP_LEFT,
TOP_CENTER,
TOP_RIGHT,
CENTER_LEFT,
CENTER,
CENTER_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT,
}
export class RiveEvents {
static onPlayEvent = 'onPlayEvent';
static onPauseEvent = 'onPauseEvent';
static onLoopEndEvent = 'onLoopEndEvent';
static onStopEvent = 'onStopEvent';
static stateChangedEvent = 'stateChangedEvent';
static receivedInputEvent = 'receivedInputEvent';
static touchBeganEvent = 'touchBeganEvent';
static touchCancelledEvent = 'touchCancelledEvent';
static touchEndedEvent = 'touchEndedEvent';
static touchMovedEvent = 'touchMovedEvent';
constructor(public view: View) {}
notifyEvent(name: string, data: any) {
this.view.notify({ eventName: name, object: this.view, data });
}
}
export abstract class RiveViewBase extends View {
/*
* Android: file in folder raw of android or path of file
* Required
* */
public src: string;
/**
* Rive events
*/
public events: RiveEvents;
/* autoplay (optional) - Opening a rive animation view or specifying new resourceName or url will make it automatically play, when it is ready.
* Default: true
* */
public autoPlay: boolean;
/* alignment. (optional) - Specifies how animation should be aligned inside rive animation view..
* Default: TypeRiveAlignment.NONE
* */
public alignment?: TypeRiveAlignment;
/*
* fit (optional) - Specifies how animation should be displayed inside rive animation view
* Default: TypeRiveFit.CONTAIN
* */
public fit?: TypeRiveFit;
/*
* artboard (optional) - Specifies which animation artboard should be displayed in rive animation view.
* Default: null
* */
public artboard?: string;
/*
* animation (optional) - Specifies which animation should be played when autoplay is set to true.
* Default: null
* */
public animation?: string;
/**
* input (optional) - Specifies which input should be used.
*/
public input?: string;
/**
* inputValue (optional) - Specifies which input value should be used.
*/
public inputValue?: boolean;
/*
* stateMachine (optional) - Specifies which stateMachine should be played when autoplay is set to true.
* Default: undefined
* */
public stateMachine?: string;
/*
* loop. (optional).
* Default: TypeRiveLoop.AUTO
* */
public loop?: TypeRiveLoop;
/**
* direction. (optional).
*/
public direction?: TypeRiveDirection;
onPlay: (animation: string) => void;
onPause: (animation: string) => void;
onStop: (animation: string) => void;
onLoopEnd: (animation: string, loopMode: TypeRiveLoop) => void;
/*
* loop: default AUTO
* direction: default AUTO
* settleInitialState: default true
* */
public abstract play(loop?: TypeRiveLoop, direction?: TypeRiveDirection, settleInitialState?: true): void;
/*
* animations: default []
* loop: default AUTO
* direction: default AUTO
* areStateMachines: default false
* settleInitialState: default true
* */
public abstract playWithAnimations(animations?: string | string[], loop?: TypeRiveLoop, direction?: TypeRiveDirection, areStateMachines?: false, settleInitialState?: true): void;
/**
* Stops all.
*/
public abstract stop(): void;
/**
* Stops any of the provided animations.
*/
public abstract stopWithAnimations(animations: string | string[], areStateMachines?: false): void;
/**
* Pauses all playing animations.
*/
public abstract pause(): void;
/*
* Pauses any of the provided animations.
* animations: default []
* areStateMachines: default false
* */
public abstract pauseWithAnimations(animations: string | string[], areStateMachines?: false): void;
/**
* Reset the view by resetting the current artboard, before any animations have been applied
*
* Note: this will respect [autoplay]
*/
public abstract reset(): void;
/*
* Fire the Trigger input called inputName on all active matching state machines
* stateMachineName - Specifies state machine name which will be matched against all active state machines.
* inputName - Specifies the name of the trigger that should be fired.
* */
public abstract fireState(stateMachineName: string, inputName: string): void;
public abstract isPlaying(): boolean;
/**
* Get the currently loaded StateMachine.
*/
public abstract getStateMachines();
/**
* * Get the currently playing StateMachine.
*/
public abstract getPlayingStateMachines();
/**
* Get the currently loaded animations.
*/
public abstract getAnimations();
/**
* Get the currently playing animations.
*/
public abstract getPlayingAnimations();
}
export const autoPlayProperty = new Property<RiveViewBase, boolean>({
name: 'autoPlay',
defaultValue: true,
valueConverter: booleanConverter,
});
autoPlayProperty.register(RiveViewBase);
export const fitProperty = new Property<RiveViewBase, TypeRiveFit>({
name: 'fit',
defaultValue: TypeRiveFit.CONTAIN,
});
fitProperty.register(RiveViewBase);
export const alignmentProperty = new Property<RiveViewBase, TypeRiveAlignment>({
name: 'alignment',
defaultValue: TypeRiveAlignment.CENTER,
});
alignmentProperty.register(RiveViewBase);
export const artboardProperty = new Property<RiveViewBase, string | null>({
name: 'artboard',
defaultValue: null,
});
artboardProperty.register(RiveViewBase);
export const animationProperty = new Property<RiveViewBase, string | null>({
name: 'animation',
defaultValue: null,
});
animationProperty.register(RiveViewBase);
export const stateMachineProperty = new Property<RiveViewBase, string | null>({
name: 'stateMachine',
defaultValue: null,
});
stateMachineProperty.register(RiveViewBase);
export const inputValueProperty = new Property<RiveViewBase, string | boolean | number | null>({
name: 'inputValue',
defaultValue: null,
});
inputValueProperty.register(RiveViewBase);
export const srcProperty = new Property<RiveViewBase, string>({
name: 'src',
});
srcProperty.register(RiveViewBase);