22
33namespace Rive . Maui ;
44
5- public partial class RivePlayerHandler ( ) : ViewHandler < RivePlayer , RiveView > ( PropertyMapper , CommandMapper )
5+ public partial class RivePlayerHandler ( ) : ViewHandler < RivePlayer , CustomRiveView > ( PropertyMapper , CommandMapper )
66{
7- protected override RiveView CreatePlatformView ( )
7+ protected override CustomRiveView CreatePlatformView ( )
88 {
9- var riveView = new RiveView ( Context , VirtualView ) ;
10- return riveView ;
9+ var platformView = new CustomRiveView ( Context ) ;
10+ platformView . VirtualView . SetTarget ( VirtualView ) ;
11+
12+ return platformView ;
1113 }
1214
13- protected override void ConnectHandler ( RiveView platformView )
15+ protected override void ConnectHandler ( CustomRiveView platformView )
1416 {
1517 platformView . CreateAnimationView ( ) ;
16- //riveView.CreateAnimationView();
1718 }
1819
19- protected override void DisconnectHandler ( RiveView platformView )
20+ protected override void DisconnectHandler ( CustomRiveView platformView )
2021 {
2122 platformView . Dispose ( ) ;
2223 }
2324
2425 public static void MapArtboardName ( RivePlayerHandler handler , RivePlayer view )
2526 {
26- if ( ! string . Equals ( handler . PlatformView . AnimationView ? . ArtboardName , view . ArtboardName , StringComparison . OrdinalIgnoreCase ) )
27+ if ( handler . PlatformView . AnimationView != null &&
28+ ! string . Equals ( handler . PlatformView . AnimationView . ArtboardName , view . ArtboardName , StringComparison . OrdinalIgnoreCase ) )
2729 handler . PlatformView . AnimationView . ArtboardName = view . ArtboardName ;
2830 }
2931
3032 public static void MapAnimationName ( RivePlayerHandler handler , RivePlayer view )
3133 {
32- if ( string . IsNullOrWhiteSpace ( view . AnimationName ) )
34+ if ( handler . PlatformView . AnimationView == null || string . IsNullOrWhiteSpace ( view . AnimationName ) )
3335 return ;
3436
3537 var riveLoop = view . Loop . AsRive ( ) ;
@@ -44,45 +46,42 @@ public static void MapAnimationName(RivePlayerHandler handler, RivePlayer view)
4446
4547 public static void MapStateMachineName ( RivePlayerHandler handler , RivePlayer view )
4648 {
49+ if ( handler . PlatformView . AnimationView == null )
50+ return ;
51+
4752 var rendererAttributes = handler . PlatformView . AnimationView . GetRendererAttributes ( ) ;
4853
4954 if ( ! string . Equals ( rendererAttributes . StateMachineName , view . StateMachineName , StringComparison . OrdinalIgnoreCase ) )
5055 rendererAttributes . StateMachineName = view . StateMachineName ;
5156 }
5257
53- public static void MapResourceName ( RivePlayerHandler handler , RivePlayer view )
54- {
55- if ( string . IsNullOrWhiteSpace ( view . ResourceName ) ||
56- string . Equals ( view . ResourceName , handler . PlatformView . ResourceName , StringComparison . OrdinalIgnoreCase ) )
57- return ;
58-
59- handler . CreatePlatformView ( ) ;
60- }
61-
6258 public static void MapAutoPlay ( RivePlayerHandler handler , RivePlayer view )
6359 {
64- if ( handler . PlatformView . AnimationView . Autoplay != view . AutoPlay )
60+ if ( handler . PlatformView . AnimationView != null && handler . PlatformView . AnimationView . Autoplay != view . AutoPlay )
6561 handler . PlatformView . AnimationView . Autoplay = view . AutoPlay ;
6662 }
6763
6864 public static void MapFit ( RivePlayerHandler handler , RivePlayer view )
6965 {
7066 var riveFit = view . Fit . AsRive ( ) ;
71- if ( handler . PlatformView . AnimationView . Fit != riveFit )
67+ if ( handler . PlatformView . AnimationView != null && handler . PlatformView . AnimationView . Fit != riveFit )
7268 handler . PlatformView . AnimationView . Fit = riveFit ;
7369 }
7470
7571 public static void MapAlignment ( RivePlayerHandler handler , RivePlayer view )
7672 {
7773 var riveAlignment = view . Alignment . AsRive ( ) ;
78- if ( handler . PlatformView . AnimationView . Alignment != riveAlignment )
74+ if ( handler . PlatformView . AnimationView != null && handler . PlatformView . AnimationView . Alignment != riveAlignment )
7975 handler . PlatformView . AnimationView . Alignment = riveAlignment ;
8076 }
8177
8278 public static void MapLoop ( RivePlayerHandler handler , RivePlayer view )
8379 {
84- var rendererAttributes = handler . PlatformView . AnimationView . GetRendererAttributes ( ) ;
85- rendererAttributes . Loop = view . Loop . AsRive ( ) ;
80+ if ( handler . PlatformView . AnimationView != null )
81+ {
82+ var rendererAttributes = handler . PlatformView . AnimationView . GetRendererAttributes ( ) ;
83+ rendererAttributes . Loop = view . Loop . AsRive ( ) ;
84+ }
8685 }
8786
8887 public static void MapDirection ( RivePlayerHandler handler , RivePlayer view )
@@ -92,13 +91,15 @@ public static void MapDirection(RivePlayerHandler handler, RivePlayer view)
9291
9392 public static void MapPlay ( RivePlayerHandler handler , RivePlayer view , object ? args )
9493 {
94+ if ( handler . PlatformView . AnimationView == null )
95+ return ;
96+
9597 var riveLoop = view . Loop . AsRive ( ) ;
9698 var riveDirection = view . Direction . AsRive ( ) ;
9799
98100 if ( ! string . IsNullOrWhiteSpace ( view . AnimationName ) )
99101 {
100102 handler . PlatformView . AnimationView . Play ( view . AnimationName , riveLoop , riveDirection , false , true ) ;
101- handler . PlatformView . RiveAnimation = handler . PlatformView . AnimationView . Animations . FirstOrDefault ( x => x . Name == view . AnimationName ) ;
102103 return ;
103104 }
104105
@@ -120,13 +121,13 @@ public static void MapPlay(RivePlayerHandler handler, RivePlayer view, object? a
120121 }
121122
122123 public static void MapPause ( RivePlayerHandler handler , RivePlayer view , object ? args )
123- => handler . PlatformView . AnimationView . Pause ( ) ;
124+ => handler . PlatformView . AnimationView ? . Pause ( ) ;
124125
125126 public static void MapStop ( RivePlayerHandler handler , RivePlayer view , object ? args )
126- => handler . PlatformView . AnimationView . Stop ( ) ;
127+ => handler . PlatformView . AnimationView ? . Stop ( ) ;
127128
128129 public static void MapReset ( RivePlayerHandler handler , RivePlayer view , object ? args )
129- => handler . PlatformView . AnimationView . Reset ( ) ;
130+ => handler . PlatformView . AnimationView ? . Reset ( ) ;
130131
131132 public static void MapSetInput ( RivePlayerHandler handler , RivePlayer view , object ? args )
132133 {
@@ -136,13 +137,13 @@ public static void MapSetInput(RivePlayerHandler handler, RivePlayer view, objec
136137 switch ( inputArgs . Value )
137138 {
138139 case double doubleValue :
139- handler . PlatformView . AnimationView . SetNumberState ( inputArgs . StateMachineName , inputArgs . InputName , ( float ) doubleValue ) ;
140+ handler . PlatformView . AnimationView ? . SetNumberState ( inputArgs . StateMachineName , inputArgs . InputName , ( float ) doubleValue ) ;
140141 break ;
141142 case float floatValue :
142- handler . PlatformView . AnimationView . SetNumberState ( inputArgs . StateMachineName , inputArgs . InputName , floatValue ) ;
143+ handler . PlatformView . AnimationView ? . SetNumberState ( inputArgs . StateMachineName , inputArgs . InputName , floatValue ) ;
143144 break ;
144145 case bool boolValue :
145- handler . PlatformView . AnimationView . SetBooleanState ( inputArgs . StateMachineName , inputArgs . InputName , boolValue ) ;
146+ handler . PlatformView . AnimationView ? . SetBooleanState ( inputArgs . StateMachineName , inputArgs . InputName , boolValue ) ;
146147 break ;
147148 }
148149 }
@@ -151,7 +152,7 @@ public static void MapTriggerInput(RivePlayerHandler handler, RivePlayer view, o
151152 {
152153 if ( args is StateMachineTriggerInputArgs triggerInputArgs )
153154 {
154- handler . PlatformView . AnimationView . FireState ( triggerInputArgs . StateMachineName , triggerInputArgs . InputName ) ;
155+ handler . PlatformView . AnimationView ? . FireState ( triggerInputArgs . StateMachineName , triggerInputArgs . InputName ) ;
155156 }
156157 }
157158}
0 commit comments