Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,63 @@ const riveRef = useRef<HybridView<RiveViewProps, RiveViewMethods>>(null);
/>
```

## Native SDK Version Customization

> **⚠️ Advanced Usage:** Customizing native SDK versions is intended for advanced users only. Using non-default versions may cause build-time errors, or compatibility issues. Always review and update custom versions when upgrading react-native-rive.

By default, react-native-rive uses specific versions of the Rive native SDKs defined in the library's `package.json` (`runtimeVersions.ios` and `runtimeVersions.android`). You can customize these versions if needed.

### Vanilla React Native

Add the appropriate properties to your configuration files:

**iOS** - Add to `ios/Podfile.properties.json`:

```json
{
"RiveRuntimeIOSVersion": "6.13.0"
}
```

**Android** - Add to `android/gradle.properties`:

```properties
Rive_RiveRuntimeAndroidVersion=10.6.0
```

### Expo

Use an inline config plugin in your `app.config.ts`:

```typescript
import { withPodfileProperties, withGradleProperties } from '@expo/config-plugins';

export default {
expo: {
// ... other config
plugins: [
(config) => {
config = withPodfileProperties(config, (config) => {
config.modResults['RiveRuntimeIOSVersion'] = '6.13.0';
return config;
});

config = withGradleProperties(config, (config) => {
config.modResults.push({
type: 'property',
key: 'Rive_RiveRuntimeAndroidVersion',
value: '10.6.0',
});
return config;
});

return config;
},
],
},
};
```

## Error Handling

All Rive operations can be wrapped in try/catch blocks for error handling:
Expand Down
30 changes: 29 additions & 1 deletion Rive.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

rive_ios_version = nil

if ENV['RIVE_RUNTIME_IOS_VERSION']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document the environment option as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively simplify and only support one option (for now)

rive_ios_version = ENV['RIVE_RUNTIME_IOS_VERSION']
end

if !rive_ios_version && defined?($RiveRuntimeIOSVersion)
rive_ios_version = $RiveRuntimeIOSVersion
end

if !rive_ios_version && defined?(Pod::Config) && Pod::Config.respond_to?(:instance)
podfile_properties_path = File.join(Pod::Config.instance.installation_root, 'Podfile.properties.json')
if File.exist?(podfile_properties_path)
podfile_properties = JSON.parse(File.read(podfile_properties_path)) rescue {}
rive_ios_version = podfile_properties['RiveRuntimeIOSVersion'] if podfile_properties['RiveRuntimeIOSVersion']
end
end

if !rive_ios_version && package['runtimeVersions'] && package['runtimeVersions']['ios']
rive_ios_version = package['runtimeVersions']['ios']
end

if !rive_ios_version
raise "Internal Error: Failed to determine Rive iOS SDK version. Please ensure package.json contains 'runtimeVersions.ios'"
end

Pod::UI.puts "react-native-rive: Rive iOS SDK #{rive_ios_version}"

Pod::Spec.new do |s|
s.name = "Rive"
s.version = package["version"]
Expand All @@ -18,7 +46,7 @@ Pod::Spec.new do |s|
load 'nitrogen/generated/ios/Rive+autolinking.rb'
add_nitrogen_files(s)

s.dependency "RiveRuntime", "6.12.0"
s.dependency "RiveRuntime", rive_ios_version

install_modules_dependencies(s)
end
25 changes: 24 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,33 @@ repositories {

def kotlin_version = getExtOrDefault("kotlinVersion")

def getRiveAndroidVersion() {
if (rootProject.ext.has('RiveRuntimeAndroidVersion')) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When/how will this be set? Should we document this option as well?

I see on iOS we also have an environment option. Does Android need the same?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into various libraries, some use this ext method some env variables. iOS/Podfile.properties.json, android/gradle.properties sounds the most straightforward to me considering expo, I've documented only that.

Not sure we need all 3. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I also don't think we need all the options. But is there then an argument to remove the option completely. Instead of just not documenting?

return rootProject.ext.get('RiveRuntimeAndroidVersion')
}

if (project.hasProperty('Rive_RiveRuntimeAndroidVersion')) {
return project.property('Rive_RiveRuntimeAndroidVersion')
}

def packageJson = file("${projectDir}/../package.json")
if (packageJson.exists()) {
def json = new groovy.json.JsonSlurper().parseText(packageJson.text)
if (json.runtimeVersions?.android) {
return json.runtimeVersions.android
}
}

throw new GradleException("Failed to determine Rive Android SDK version. Please ensure package.json contains 'runtimeVersions.android'")
}

def riveAndroidVersion = getRiveAndroidVersion()
println "react-native-rive: Rive Android SDK ${riveAndroidVersion}"

dependencies {
implementation "com.facebook.react:react-android"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'app.rive:rive-android:10.5.0'
implementation "app.rive:rive-android:${riveAndroidVersion}"
implementation "androidx.startup:startup-runtime:1.2.0"
implementation project(":react-native-nitro-modules")
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
"url": "https://github.com/rive-app/rive-nitro-react-native/issues"
},
"homepage": "https://github.com/rive-app/rive-nitro-react-native#readme",
"runtimeVersions": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice

"ios": "6.12.0",
"android": "10.5.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
Expand Down
Loading