diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2455ca01..34cd16d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,9 @@ jobs: - name: Lint files run: yarn lint + - name: Codegen + run: yarn nitrogen + - name: Typecheck files run: yarn typecheck @@ -47,6 +50,9 @@ jobs: - name: Setup uses: ./.github/actions/setup + - name: Build package + run: yarn nitrogen + - name: Build package run: yarn prepare @@ -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" @@ -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 @@ -154,6 +164,7 @@ jobs: - name: Install cocoapods if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true' run: | + yarn nitrogen cd example bundle install bundle exec pod install --project-directory=ios diff --git a/example/Gemfile b/example/Gemfile index 6a4c5f17..b6878a2d 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -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. diff --git a/example/Gemfile.lock b/example/Gemfile.lock index a99701f5..f0eb9f27 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b8c1f702..3fa473af 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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 @@ -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 diff --git a/package.json b/package.json index 28be75fb..827817be 100644 --- a/package.json +++ b/package.json @@ -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", @@ -143,8 +143,7 @@ [ "custom", { - "script": "nitrogen", - "clean": "nitrogen/" + "script": "nitrogen" } ], [ diff --git a/src/hooks/useRiveBoolean.ts b/src/hooks/useRiveBoolean.ts index 5e762d44..42c9ad57 100644 --- a/src/hooks/useRiveBoolean.ts +++ b/src/hooks/useRiveBoolean.ts @@ -1,4 +1,3 @@ -import { useCallback } from 'react'; import { type ViewModelBooleanProperty, type ViewModelInstance, @@ -6,6 +5,10 @@ import { 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. * @@ -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 }; } diff --git a/src/hooks/useRiveColor.ts b/src/hooks/useRiveColor.ts index a56db986..3e9a9c30 100644 --- a/src/hooks/useRiveColor.ts +++ b/src/hooks/useRiveColor.ts @@ -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. * @@ -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; diff --git a/src/hooks/useRiveNumber.ts b/src/hooks/useRiveNumber.ts index f2ad5284..1e06979f 100644 --- a/src/hooks/useRiveNumber.ts +++ b/src/hooks/useRiveNumber.ts @@ -1,4 +1,3 @@ -import { useCallback } from 'react'; import { type ViewModelInstance, type ViewModelNumberProperty, @@ -6,6 +5,10 @@ import { 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. * @@ -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 }; } diff --git a/src/hooks/useRiveString.ts b/src/hooks/useRiveString.ts index c6deab43..16216c8b 100644 --- a/src/hooks/useRiveString.ts +++ b/src/hooks/useRiveString.ts @@ -1,4 +1,3 @@ -import { useCallback } from 'react'; import { type ViewModelInstance, type ViewModelStringProperty, @@ -6,6 +5,10 @@ import { 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. * @@ -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 }; } diff --git a/src/hooks/useRiveTrigger.ts b/src/hooks/useRiveTrigger.ts index 7ba753ab..4a478006 100644 --- a/src/hooks/useRiveTrigger.ts +++ b/src/hooks/useRiveTrigger.ts @@ -1,4 +1,4 @@ -import { useCallback } from 'react'; +import { useCallback, useMemo } from 'react'; import { type ViewModelInstance, type ViewModelTriggerProperty, @@ -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. * @@ -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) {