Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit d95944d

Browse files
committed
Added text runs
1 parent 51ca600 commit d95944d

File tree

9 files changed

+64
-5
lines changed

9 files changed

+64
-5
lines changed

samples/Example/App.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ public partial class App : Application
77
public App()
88
{
99
InitializeComponent();
10+
}
1011

11-
MainPage = new NavigationPage(new MainPage());
12+
protected override Window CreateWindow(IActivationState? activationState)
13+
{
14+
return new Window(new NavigationPage(new MainPage()));
1215
}
1316
}

src/Rive.Maui/Platforms/Android/CustomRiveView.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public void CreateAnimationView()
6565
_eventListener.RiveViewReference.SetTarget(this);
6666
animationView.AddEventListener(_eventListener);
6767

68+
if (virtualView.TextRuns != null)
69+
{
70+
foreach (var textRun in virtualView.TextRuns)
71+
{
72+
animationView.SetTextRunValue(textRun.TextRunName, textRun.Value);
73+
}
74+
}
75+
6876
AnimationView = animationView;
6977
}
7078

src/Rive.Maui/Platforms/Android/RivePlayerHandler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,12 @@ public static void MapTriggerInput(RivePlayerHandler handler, RivePlayer view, o
155155
handler.PlatformView.AnimationView?.FireState(triggerInputArgs.StateMachineName, triggerInputArgs.InputName);
156156
}
157157
}
158+
159+
public static void MapSetTextRun(RivePlayerHandler handler, RivePlayer view, object? args)
160+
{
161+
if (args is TextRun setTextRun)
162+
{
163+
handler.PlatformView.AnimationView?.SetTextRunValue(setTextRun.TextRunName, setTextRun.Value);
164+
}
165+
}
158166
}

src/Rive.Maui/Platforms/iOS/CustomRiveView.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public void UpdateAnimation()
114114
? _riveFile?.ArtboardFromName(ArtboardName, out _)
115115
: _riveFile?.Artboard(out _);
116116

117+
if (VirtualView.TryGetTarget(out var rivePlayer) && rivePlayer.TextRuns?.Count > 0)
118+
{
119+
foreach (var textRun in rivePlayer.TextRuns)
120+
{
121+
SetTextRun(textRun.TextRunName, textRun.Value);
122+
}
123+
}
124+
117125
if (!string.IsNullOrWhiteSpace(AnimationName) || _riveArtboard?.StateMachineCount == 0)
118126
{
119127
_riveAnimation?.Dispose();
@@ -309,6 +317,15 @@ public void TriggerInput(string stateMachineName, string inputName)
309317
_riveStateMachine?.GetTrigger(inputName)?.Fire();
310318
}
311319

320+
public void SetTextRun(string textRunName, string value)
321+
{
322+
var textRun = _riveArtboard?.TextRun(textRunName);
323+
if (textRun != null)
324+
{
325+
textRun.Text = value;
326+
}
327+
}
328+
312329
public void ResetProperties(bool disposeFile = true)
313330
{
314331
_resourceName = null;

src/Rive.Maui/Platforms/iOS/RivePlayerHandler.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,12 @@ public static void MapTriggerInput(RivePlayerHandler handler, RivePlayer view, o
124124
handler.PlatformView.TriggerInput(triggerInputArgs.StateMachineName, triggerInputArgs.InputName);
125125
}
126126
}
127+
128+
public static void MapSetTextRun(RivePlayerHandler handler, RivePlayer view, object? args)
129+
{
130+
if (args is TextRun setTextRun)
131+
{
132+
handler.PlatformView.SetTextRun(setTextRun.TextRunName, setTextRun.Value);
133+
}
134+
}
127135
}

src/Rive.Maui/RivePlayer.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ public event EventHandler<string> EventReceived
108108
typeof(RivePlayer)
109109
);
110110

111+
public static readonly BindableProperty TextRunsProperty = BindableProperty.Create(
112+
nameof(TextRuns),
113+
typeof(List<TextRun>),
114+
typeof(RivePlayer)
115+
);
116+
111117
public string? ArtboardName
112118
{
113119
get => (string?)GetValue(ArtboardNameProperty);
@@ -186,6 +192,12 @@ public List<DynamicAsset>? DynamicAssets
186192
set => SetValue(DynamicAssetsProperty, value);
187193
}
188194

195+
public List<TextRun>? TextRuns
196+
{
197+
get => (List<TextRun>?)GetValue(TextRunsProperty);
198+
set => SetValue(TextRunsProperty, value);
199+
}
200+
189201
public ICommand PlayCommand
190202
=> new Command(Play);
191203

@@ -219,6 +231,9 @@ public void SetInput(StateMachineInputArgs args)
219231
public void TriggerInput(StateMachineTriggerInputArgs args)
220232
=> Handler?.Invoke(nameof(TriggerInput), args);
221233

234+
public void SetTextRun(TextRun args)
235+
=> Handler?.Invoke(nameof(SetTextRun), args);
236+
222237
protected override void OnHandlerChanged()
223238
{
224239
if (Handler == null) return;

src/Rive.Maui/RivePlayerEnums.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public enum RiveIOSRendererType
5454

5555
public enum RivePlayerEvent
5656
{
57-
#if IOS
58-
GeneralEvent = 407,
59-
#else
6057
GeneralEvent,
61-
#endif
6258
OpenURLEvent
6359
}

src/Rive.Maui/RivePlayerHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ public partial class RivePlayerHandler
2323
[nameof(RivePlayer.Reset)] = MapReset,
2424
[nameof(RivePlayer.SetInput)] = MapSetInput,
2525
[nameof(RivePlayer.TriggerInput)] = MapTriggerInput,
26+
[nameof(RivePlayer.SetTextRun)] = MapSetTextRun,
2627
};
2728
}

src/Rive.Maui/TextRun.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Rive.Maui;
2+
3+
public record TextRun(string TextRunName, string Value);

0 commit comments

Comments
 (0)