Skip to content

Commit

Permalink
feat: fallback to only use the asset name as a key
Browse files Browse the repository at this point in the history
  • Loading branch information
HayesGordon committed Feb 4, 2025
1 parent 78c15c8 commit 5138fa4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ private class RiveReactNativeAssetStore(
private val referencedAssets: ReadableMap, private val loadAssetHandler: LoadAssetHandler
) : FileAssetLoader() {
override fun loadContents(asset: FileAsset, inBandBytes: ByteArray): Boolean {
val assetData = referencedAssets.getMap(asset.uniqueFilename.substringBeforeLast("."))
var assetData = referencedAssets.getMap(asset.uniqueFilename.substringBeforeLast("."))
if (assetData == null) {
assetData = referencedAssets.getMap(asset.name)
}

val source = assetData?.getMap("source") ?: return false // Do not handle the asset.

Expand Down
18 changes: 10 additions & 8 deletions example/src/OutOfBandAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ export default function StateMachine() {
fit={Fit.Contain}
style={styles.box}
stateMachineName="State Machine 1"
// You can use the `referencedAssets` prop to load in external assets from a URI
// or bundled asset on the native platform (iOS and Android)
// or as a source loaded directly from JavaScript.
// The `referencedAssets` prop allows you to load external assets from various sources:
// - A URI
// - A bundled asset on the native platform (iOS and Android)
// - A source loaded directly from JavaScript.
//
// Below demonstrates various ways to load in the same asset
// located in different places. Its not needed to store the same
// asset in all these locations, but this example does that for
// demonstration purposes.
// This example demonstrates multiple ways to load the same asset from different locations.
// Note: It's not necessary to store the same asset in all these locations; this is for demonstration purposes.
//
// The key of the map is the unique asset identifier (as exported in the Editor),
// which is a combination of the asset name and its unique identifier.
// which combines the asset name and its unique identifier.
// You can optionally exclude the unique identifier, for example, instead of 'Inter-594377', you can use 'Inter'.
// However, it is recommended to use the full identifier to avoid potential conflicts.
// Using just the asset name allows you to avoid knowing the unique identifier and gives you more control over naming.
referencedAssets={{
'Inter-594377': {
source: require('./assets/Inter-594377.ttf'),
Expand Down
2 changes: 1 addition & 1 deletion ios/RiveReactNativeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate
}

private func customLoader(asset: RiveFileAsset, data: Data, factory: RiveFactory) -> Bool {
guard let assetData = referencedAssets?[asset.uniqueName()] as? NSDictionary else {
guard let assetData = referencedAssets?[asset.uniqueName()] as? NSDictionary ?? referencedAssets?[asset.name()] as? NSDictionary else {
return false
}

Expand Down

0 comments on commit 5138fa4

Please sign in to comment.