Skip to content

Commit a2d44a9

Browse files
committed
feat: rename public TS API to RiveLog, hook into iOS SDK's pluggable logger
Renames the exported namespace from RiveLogger to RiveLog to match the native SDK naming convention. Implements RiveRuntime.RiveLog.Logger on iOS to unify C++ runtime logs through our bridge logging system (parity with Android's RiveErrorLogger).
1 parent 090d1e4 commit a2d44a9

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

ios/new/HybridRiveFileFactory.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ final class HybridRiveFileFactory: HybridRiveFileFactorySpec, @unchecked Sendabl
66

77
// All files must share the same Worker so artboard handles are valid across files
88
// (each Worker has its own C++ command server with its own m_artboards map)
9-
private static let sharedWorkerTask = Task { @MainActor in try await Worker() }
9+
private static let sharedWorkerTask = Task { @MainActor in
10+
if !(RiveRuntime.RiveLog.logger is RiveRuntimeLogger) {
11+
RiveRuntime.RiveLog.logger = RiveRuntimeLogger()
12+
}
13+
return try await Worker()
14+
}
1015

1116
func fromURL(url: String, loadCdn: Bool, referencedAssets: ReferencedAssetsType?) throws
1217
-> Promise<(any HybridRiveFileSpec)>

ios/new/RiveRuntimeLogger.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@_spi(RiveExperimental) import RiveRuntime
2+
3+
/// Implements the Rive iOS SDK's `RiveLog.Logger` protocol and forwards all
4+
/// C++ runtime logs through our bridge-level `RiveLog` utility, giving JS
5+
/// visibility into file, artboard, state machine, and view model diagnostics.
6+
final class RiveRuntimeLogger: RiveRuntime.RiveLog.Logger, @unchecked Sendable {
7+
func notice(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
8+
RiveLog.i(tag.category, message())
9+
}
10+
11+
func debug(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
12+
RiveLog.d(tag.category, message())
13+
}
14+
15+
func trace(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
16+
RiveLog.d(tag.category, message())
17+
}
18+
19+
func info(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
20+
RiveLog.i(tag.category, message())
21+
}
22+
23+
func error(tag: RiveRuntime.RiveLog.Tag, error: (any Error)?, _ message: @escaping () -> String) {
24+
let suffix = error.map { " (\($0.localizedDescription))" } ?? ""
25+
RiveLog.e(tag.category, "\(message())\(suffix)")
26+
}
27+
28+
func warning(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
29+
RiveLog.w(tag.category, message())
30+
}
31+
32+
func fault(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
33+
RiveLog.e(tag.category, message())
34+
}
35+
36+
func critical(tag: RiveRuntime.RiveLog.Tag, _ message: @escaping () -> String) {
37+
RiveLog.e(tag.category, message())
38+
}
39+
}

src/core/RiveLogger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function defaultHandler(level: string, tag: string, message: string) {
1616

1717
_logger.setHandler(defaultHandler);
1818

19-
export namespace RiveLogger {
19+
export namespace RiveLog {
2020
export function setHandler(
2121
handler: (level: string, tag: string, message: string) => void
2222
) {

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ export { useRiveFile, type UseRiveFileResult } from './hooks/useRiveFile';
6666
export { type RiveFileInput } from './hooks/useRiveFile';
6767
export { type SetValueAction } from './types';
6868
export { RiveRuntime } from './core/RiveRuntime';
69-
export { RiveLogger } from './core/RiveLogger';
69+
export { RiveLog } from './core/RiveLogger';
7070
export { DataBindMode };

0 commit comments

Comments
 (0)