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
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Lint files
run: yarn lint

- name: Codegen
run: yarn nitrogen

- name: Typecheck files
run: yarn typecheck

Expand All @@ -47,6 +50,9 @@ jobs:
- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn nitrogen

- name: Build package
run: yarn prepare

Expand Down Expand Up @@ -100,6 +106,10 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

- name: Generate nitrogen code
if: env.turbo_cache_hit != 1
run: yarn nitrogen

- name: Build example for Android
env:
JAVA_OPTS: "-XX:MaxHeapSize=6g"
Expand All @@ -109,7 +119,7 @@ jobs:
build-ios:
runs-on: macos-latest
env:
XCODE_VERSION: 16.2
XCODE_VERSION: 16.4
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
Expand Down Expand Up @@ -154,6 +164,7 @@ jobs:
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn nitrogen
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.

Can decide this later, but might prefer to commit the nitrogen generated code

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.

👍 Yes let's do that, otherwise it's a pain with for example builder bob. Ideally we'd have a gh action that checks if the generated files are uptodate.

cd example
bundle install
bundle exec pod install --project-directory=ios
Expand Down
4 changes: 2 additions & 2 deletions example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ source 'https://rubygems.org'
ruby ">= 2.6.10"

# Exclude problematic versions of cocoapods and activesupport that causes build failures.
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
gem 'cocoapods', '>= 1.16'
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
gem 'xcodeproj', '< 1.26.0'
gem 'xcodeproj', '>= 1.27.0', '< 2.0'
gem 'concurrent-ruby', '< 1.3.4'

# Ruby 3.4.0 has removed some libraries from the standard library.
Expand Down
55 changes: 32 additions & 23 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@ GEM
base64
nkf
rexml
activesupport (6.1.7.10)
activesupport (7.1.5.2)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
securerandom (>= 0.3)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
base64 (0.3.0)
benchmark (0.5.0)
bigdecimal (3.3.1)
claide (1.1.0)
cocoapods (1.15.2)
cocoapods (1.16.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.15.2)
cocoapods-core (= 1.16.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
Expand All @@ -38,8 +45,8 @@ GEM
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.15.2)
xcodeproj (>= 1.27.0, < 2.0)
cocoapods-core (1.16.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
Expand All @@ -60,8 +67,10 @@ GEM
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.3.3)
connection_pool (2.5.4)
drb (2.2.3)
escape (0.0.4)
ethon (0.16.0)
ethon (0.15.0)
ffi (>= 1.15.0)
ffi (1.17.2)
fourflusher (2.3.1)
Expand All @@ -71,30 +80,30 @@ GEM
mutex_m
i18n (1.14.7)
concurrent-ruby (~> 1.0)
json (2.7.6)
json (2.15.2)
logger (1.7.0)
minitest (5.25.4)
minitest (5.26.0)
molinillo (0.8.0)
mutex_m (0.3.0)
nanaimo (0.3.0)
nanaimo (0.4.0)
nap (1.1.0)
netrc (0.11.0)
nkf (0.2.0)
public_suffix (4.0.7)
rexml (3.4.1)
rexml (3.4.4)
ruby-macho (2.5.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
securerandom (0.3.2)
typhoeus (1.5.0)
ethon (>= 0.9.0, < 0.16.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.25.1)
xcodeproj (1.27.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
zeitwerk (2.6.18)

PLATFORMS
ruby
Expand All @@ -103,14 +112,14 @@ DEPENDENCIES
activesupport (>= 6.1.7.5, != 7.1.0)
benchmark
bigdecimal
cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
cocoapods (>= 1.16)
concurrent-ruby (< 1.3.4)
logger
mutex_m
xcodeproj (< 1.26.0)
xcodeproj (>= 1.27.0, < 2.0)

RUBY VERSION
ruby 2.6.10p210
ruby 2.7.8p225

BUNDLED WITH
1.17.2
2.4.22
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ SPEC CHECKSUMS:
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
hermes-engine: 314be5250afa5692b57b4dd1705959e1973a8ebe
NitroModules: 4e92fa5218beff179daf51714fd117e829027dd3
RCT-Folly: e78785aa9ba2ed998ea4151e314036f6c49e6d82
RCT-Folly: 36fe2295e44b10d831836cc0d1daec5f8abcf809
RCTDeprecation: 83ffb90c23ee5cea353bd32008a7bca100908f8c
RCTRequired: eb7c0aba998009f47a540bec9e9d69a54f68136e
RCTTypeSafety: 659ae318c09de0477fd27bbc9e140071c7ea5c93
Expand Down Expand Up @@ -2112,13 +2112,13 @@ SPEC CHECKSUMS:
React-timing: a90f4654cbda9c628614f9bee68967f1768bd6a5
React-utils: a612d50555b6f0f90c74b7d79954019ad47f5de6
ReactAppDependencyProvider: 04d5eb15eb46be6720e17a4a7fa92940a776e584
ReactCodegen: c63eda03ba1d94353fb97b031fc84f75a0d125ba
ReactCodegen: f37719863f9355a030dff77c98f59b7206333add
ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0
Rive: 273bc013df446eeaf8e9049a72033095ec339dde
RiveRuntime: 1e72d73bea430242387177b9d0aa95126406b462
RNGestureHandler: ebef699ea17e7c0006c1074e1e423ead60ce0121
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: c758bfb934100bb4bf9cbaccb52557cee35e8bdf
Yoga: 9f110fc4b7aa538663cba3c14cbb1c335f43c13f

PODFILE CHECKSUM: 6974e58448067deb1048e3b4490e929f624eea3c

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"typecheck": "tsc",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
"prepare": "bob build",
"prepare": "yarn nitrogen && bob build",
"nitrogen": "nitro-codegen",
"release": "release-it",
"dev:ios": "cd example && xed ios",
Expand Down Expand Up @@ -143,8 +143,7 @@
[
"custom",
{
"script": "nitrogen",
"clean": "nitrogen/"
"script": "nitrogen"
}
],
[
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useRiveBoolean.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useCallback } from 'react';
import {
type ViewModelBooleanProperty,
type ViewModelInstance,
} from '../specs/ViewModel.nitro';
import type { UseRivePropertyResult } from '../types';
import { useRiveProperty } from './useRiveProperty';

const BOOLEAN_PROPERTY_OPTIONS = {
getProperty: (vmi: ViewModelInstance, p: string) => vmi.booleanProperty(p),
};

/**
* Hook for interacting with boolean ViewModel instance properties.
*
Expand All @@ -20,8 +23,6 @@ export function useRiveBoolean(
const [value, setValue, error] = useRiveProperty<
ViewModelBooleanProperty,
boolean
>(viewModelInstance, path, {
getProperty: useCallback((vmi, p) => vmi.booleanProperty(p), []),
});
>(viewModelInstance, path, BOOLEAN_PROPERTY_OPTIONS);
return { value, setValue, error };
}
8 changes: 5 additions & 3 deletions src/hooks/useRiveColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { type UseRivePropertyResult } from '../types';
import { useRiveProperty } from './useRiveProperty';
import { RiveColor } from '../core/RiveColor';

const COLOR_PROPERTY_OPTIONS = {
getProperty: (vmi: ViewModelInstance, p: string) => vmi.colorProperty(p),
};

/**
* Hook for interacting with color ViewModel instance properties.
*
Expand All @@ -23,9 +27,7 @@ export function useRiveColor(
const [rawValue, setRawValue, error] = useRiveProperty<
ViewModelColorProperty,
number
>(viewModelInstance, path, {
getProperty: useCallback((vmi, p) => vmi.colorProperty(p), []),
});
>(viewModelInstance, path, COLOR_PROPERTY_OPTIONS);

const value =
rawValue !== undefined ? RiveColor.fromInt(rawValue) : undefined;
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useRiveNumber.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useCallback } from 'react';
import {
type ViewModelInstance,
type ViewModelNumberProperty,
} from '../specs/ViewModel.nitro';
import type { UseRivePropertyResult } from '../types';
import { useRiveProperty } from './useRiveProperty';

const NUMBER_PROPERTY_OPTIONS = {
getProperty: (vmi: ViewModelInstance, p: string) => vmi.numberProperty(p),
};

/**
* Hook for interacting with number ViewModel instance properties.
*
Expand All @@ -20,8 +23,6 @@ export function useRiveNumber(
const [value, setValue, error] = useRiveProperty<
ViewModelNumberProperty,
number
>(viewModelInstance, path, {
getProperty: useCallback((vmi, p) => vmi.numberProperty(p), []),
});
>(viewModelInstance, path, NUMBER_PROPERTY_OPTIONS);
return { value, setValue, error };
}
9 changes: 5 additions & 4 deletions src/hooks/useRiveString.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useCallback } from 'react';
import {
type ViewModelInstance,
type ViewModelStringProperty,
} from '../specs/ViewModel.nitro';
import type { UseRivePropertyResult } from '../types';
import { useRiveProperty } from './useRiveProperty';

const STRING_PROPERTY_OPTIONS = {
getProperty: (vmi: ViewModelInstance, p: string) => vmi.stringProperty(p),
};

/**
* Hook for interacting with string ViewModel instance properties.
*
Expand All @@ -20,8 +23,6 @@ export function useRiveString(
const [value, setValue, error] = useRiveProperty<
ViewModelStringProperty,
string
>(viewModelInstance, path, {
getProperty: useCallback((vmi, p) => vmi.stringProperty(p), []),
});
>(viewModelInstance, path, STRING_PROPERTY_OPTIONS);
return { value, setValue, error };
}
19 changes: 14 additions & 5 deletions src/hooks/useRiveTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import {
type ViewModelInstance,
type ViewModelTriggerProperty,
Expand All @@ -9,6 +9,9 @@ import type {
} from '../types';
import { useRiveProperty } from './useRiveProperty';

const getTriggerProperty = (vmi: ViewModelInstance, p: string) =>
vmi.triggerProperty(p);

/**
* Hook for interacting with trigger ViewModel instance properties.
*
Expand All @@ -22,13 +25,19 @@ export function useRiveTrigger(
params?: UseViewModelInstanceTriggerParameters
): UseRiveTriggerResult {
const { onTrigger } = params ?? {};

const triggerOptions = useMemo(
() => ({
getProperty: getTriggerProperty,
onPropertyEventOverride: onTrigger,
}),
[onTrigger]
);

const [_, __, error, property] = useRiveProperty<
ViewModelTriggerProperty,
undefined
>(viewModelInstance, path, {
getProperty: useCallback((vmi, p) => vmi.triggerProperty(p), []),
onPropertyEventOverride: onTrigger,
});
>(viewModelInstance, path, triggerOptions);

const trigger = useCallback(() => {
if (property) {
Expand Down
Loading