-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose Rive RendererType to choose renderer
- Loading branch information
1 parent
092813a
commit 88cac53
Showing
11 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// RNRiveRendererType.swift | ||
// rive-react-native | ||
// | ||
// Created by Peter G Hayes on 31/05/2024. | ||
// | ||
|
||
import Foundation | ||
import RiveRuntime | ||
|
||
enum RNRiveRendererType: String { | ||
case Rive = "riveRenderer" | ||
case Skia = "skiaRenderer" | ||
case CoreGraphics = "cgRenderer" | ||
|
||
static func mapToRNRiveRendererType(value: String) -> RNRiveRendererType { | ||
if let rnEnum = RNRiveRendererType(rawValue: value) { | ||
return rnEnum | ||
} else { | ||
fatalError("Unsupported renderer type: \(value)") | ||
} | ||
} | ||
|
||
static func mapToRendererType(rnRendererType: RNRiveRendererType) -> RendererType { | ||
switch rnRendererType { | ||
case .Rive: | ||
return RendererType.riveRenderer | ||
case .Skia: | ||
return RendererType.skiaRenderer | ||
case .CoreGraphics: | ||
return RendererType.cgRenderer | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RiveReactNativeRendererModule.swift | ||
// rive-react-native | ||
// | ||
// Created by Peter G Hayes on 31/05/2024. | ||
// | ||
|
||
import Foundation | ||
import RiveRuntime | ||
|
||
@objc(RiveReactNativeRendererModule) | ||
class RiveReactNativeRendererModule: NSObject { | ||
|
||
@objc(defaultRenderer:androidRenderer:) | ||
func defaultRenderer(_ iosRenderer: String, androidRenderer: String) -> Void { | ||
let rnRendererType = RNRiveRendererType.mapToRNRiveRendererType(value: iosRenderer) | ||
RenderContextManager.shared().defaultRenderer = RNRiveRendererType.mapToRendererType(rnRendererType: rnRendererType) | ||
} | ||
// Required to register the module with React Native | ||
@objc static func requiresMainQueueSetup() -> Bool { | ||
return true | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// RiveReactNativeRendererModuleBridge.m | ||
// rive-react-native | ||
// | ||
// Created by Peter G Hayes on 31/05/2024. | ||
// | ||
|
||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RCT_EXTERN_MODULE(RiveReactNativeRendererModule, NSObject) | ||
|
||
RCT_EXTERN_METHOD(defaultRenderer:(NSString *)iosRenderer androidRenderer:(NSString *)androidRenderer) | ||
|
||
@end |
28 changes: 28 additions & 0 deletions
28
android/src/main/java/com/rivereactnative/RNRiveRendererType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.rivereactnative | ||
|
||
import app.rive.runtime.kotlin.core.RendererType | ||
|
||
enum class RNRiveRendererType(private val rendererTypeName: String) { | ||
Rive("riveRenderer"), | ||
Skia("skiaRenderer"), | ||
Canvas("canvasRenderer"); | ||
|
||
override fun toString(): String { | ||
return rendererTypeName | ||
} | ||
|
||
companion object { | ||
fun mapToRNRiveRendererType(rendererType: String): RNRiveRendererType { | ||
return values().first { it.rendererTypeName == rendererType } | ||
} | ||
|
||
fun mapToRiveRendererType(rnRendererType: RNRiveRendererType): RendererType { | ||
return when (rnRendererType) { | ||
Rive -> RendererType.Rive | ||
Skia -> RendererType.Skia | ||
Canvas -> RendererType.Canvas | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
android/src/main/java/com/rivereactnative/RiveReactNativeRendererModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.rivereactnative | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.ReactMethod | ||
import app.rive.runtime.kotlin.core.Rive | ||
|
||
class RiveReactNativeRendererModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
override fun getName() = "RiveReactNativeRendererModule" | ||
|
||
@ReactMethod fun defaultRenderer(iosRenderer: String, androidRenderer: String) { | ||
val rnRendererType = RNRiveRendererType.mapToRNRiveRendererType(androidRenderer); | ||
val rendererType = RNRiveRendererType.mapToRiveRendererType(rnRendererType); | ||
Rive.init(reactApplicationContext, defaultRenderer = rendererType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { AppRegistry } from 'react-native'; | ||
import App from './src/App'; | ||
import { name as appName } from './app.json'; | ||
import Main from './src/App'; | ||
|
||
AppRegistry.registerComponent(appName, () => App); | ||
AppRegistry.registerComponent(appName, () => Main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from './types'; | ||
import Rive from './Rive'; | ||
import Rive, { RiveRenderer } from './Rive'; | ||
|
||
export { RiveRenderer }; | ||
|
||
export default Rive; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters