Skip to content

Commit

Permalink
feat: added ios simple example (#27)
Browse files Browse the repository at this point in the history
* feat: updated pod source and added example file

* feat: added simple ios example
  • Loading branch information
TMaszko authored May 20, 2021
1 parent a2a7ebf commit 8351e67
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 175 deletions.
Binary file added example/android/app/src/main/res/raw/truck_v7.riv
Binary file not shown.
Binary file added example/ios/Assets/truck_v7.riv
Binary file not shown.
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target 'RiveReactNativeExample' do
use_react_native!(:path => config["reactNativePath"])

pod 'rive-react-native', :path => '../..'
pod 'RiveRuntime', :git => 'https://github.com/callstack-internal/RiveFramework.git'
pod 'RiveRuntime', :git => 'https://github.com/rive-app/test-ios.git'

# Enables Flipper.
#
Expand Down
14 changes: 7 additions & 7 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ PODS:
- rive-react-native (0.1.0):
- React-Core
- RiveRuntime
- RiveRuntime (0.0.5)
- RiveRuntime (0.0.3)
- RNCMaskedView (0.1.11):
- React
- RNCPicker (1.16.0):
Expand Down Expand Up @@ -401,7 +401,7 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- rive-react-native (from `../..`)
- RiveRuntime (from `https://github.com/callstack-internal/RiveFramework.git`)
- RiveRuntime (from `https://github.com/rive-app/test-ios.git`)
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- "RNCPicker (from `../node_modules/@react-native-picker/picker`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
Expand Down Expand Up @@ -480,7 +480,7 @@ EXTERNAL SOURCES:
rive-react-native:
:path: "../.."
RiveRuntime:
:git: https://github.com/callstack-internal/RiveFramework.git
:git: https://github.com/rive-app/test-ios.git
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNCPicker:
Expand All @@ -496,8 +496,8 @@ EXTERNAL SOURCES:

CHECKOUT OPTIONS:
RiveRuntime:
:commit: cc8984b15746af9f271f4cc59ffa04e48990bcc3
:git: https://github.com/callstack-internal/RiveFramework.git
:commit: 497da973e950dfc117414a648d477143fa3c89da
:git: https://github.com/rive-app/test-ios.git

SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
Expand Down Expand Up @@ -538,7 +538,7 @@ SPEC CHECKSUMS:
React-RCTVibration: ae4f914cfe8de7d4de95ae1ea6cc8f6315d73d9d
ReactCommon: 73d79c7039f473b76db6ff7c6b159c478acbbb3b
rive-react-native: 78ec9539067d4c4c2201a66ff1de735e67e68f9d
RiveRuntime: 16e3ea7b8e50886eeee9e6f4ce802b603eb97289
RiveRuntime: caef28465be0ac1d011da7f4519d8349a3930cfe
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNCPicker: 918e98b54a141791e99614b1c320ef2e58300490
RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211
Expand All @@ -547,6 +547,6 @@ SPEC CHECKSUMS:
Yoga: 4bd86afe9883422a7c4028c00e34790f560923d6
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: decc314aa4ef3fffdebc04395ccc65433a79d821
PODFILE CHECKSUM: 393a22f7cdc9e51ef63f6fe2cde315006e6d1517

COCOAPODS: 1.10.1
4 changes: 4 additions & 0 deletions example/ios/RiveReactNativeExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
4C39C56BAD484C67AA576FFA /* libPods-RiveReactNativeExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CA3E69C5B9553B26FBA2DF04 /* libPods-RiveReactNativeExample.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
9D4FE6122649427F0098BF6A /* bird.riv in Resources */ = {isa = PBXBuildFile; fileRef = 9D4FE6112649427F0098BF6A /* bird.riv */; };
9D879D00265642BA00D01424 /* truck_v7.riv in Resources */ = {isa = PBXBuildFile; fileRef = 9D879CFF265642BA00D01424 /* truck_v7.riv */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -53,6 +54,7 @@
47F7ED3B7971BE374F7B8635 /* Pods-RiveReactNativeExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiveReactNativeExample.debug.xcconfig"; path = "Target Support Files/Pods-RiveReactNativeExample/Pods-RiveReactNativeExample.debug.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RiveReactNativeExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
9D4FE6112649427F0098BF6A /* bird.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = bird.riv; sourceTree = "<group>"; };
9D879CFF265642BA00D01424 /* truck_v7.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = truck_v7.riv; sourceTree = "<group>"; };
CA3E69C5B9553B26FBA2DF04 /* libPods-RiveReactNativeExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RiveReactNativeExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
E00ACF0FDA8BF921659E2F9A /* Pods-RiveReactNativeExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiveReactNativeExample.release.xcconfig"; path = "Target Support Files/Pods-RiveReactNativeExample/Pods-RiveReactNativeExample.release.xcconfig"; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -179,6 +181,7 @@
9D4FE60A26493B460098BF6A /* Assets */ = {
isa = PBXGroup;
children = (
9D879CFF265642BA00D01424 /* truck_v7.riv */,
9D4FE6112649427F0098BF6A /* bird.riv */,
);
path = Assets;
Expand Down Expand Up @@ -323,6 +326,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9D879D00265642BA00D01424 /* truck_v7.riv in Resources */,
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
9D4FE6122649427F0098BF6A /* bird.riv in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
Expand Down
6 changes: 3 additions & 3 deletions example/src/Simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import * as React from 'react';
import { SafeAreaView, StyleSheet, ScrollView } from 'react-native';
import Rive from 'rive-react-native';

const resourceName = 'truck_v7';

export default function Simple() {
return (
<SafeAreaView style={styles.safeAreaViewContainer}>
<ScrollView contentContainerStyle={styles.container}>
<Rive style={styles.animation} resourceName={'flying_car'} />
<Rive style={styles.animation} resourceName={resourceName} />
</ScrollView>
</SafeAreaView>
);
Expand All @@ -20,11 +22,9 @@ const styles = StyleSheet.create({
flexGrow: 1,
alignItems: 'center',
justifyContent: 'center',
marginBottom: 150,
},
animation: {
width: '100%',
height: 400,
marginVertical: 20,
},
});
4 changes: 3 additions & 1 deletion example/src/SimpleControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SafeAreaView, StyleSheet, ScrollView, View } from 'react-native';
import Rive, { RiveRef } from 'rive-react-native';
import { Button, Text } from 'react-native-paper';

const resourceName = 'truck_v7';

const BUTTONS = ['stop', 'play', 'pause'] as const;
type ButtonsKey = typeof BUTTONS[number];

Expand Down Expand Up @@ -39,7 +41,7 @@ export default function SimpleControls() {
ref={riveRef}
style={styles.box}
autoplay={false}
resourceName={'flying_car'}
resourceName={resourceName}
/>

<View style={styles.controls}>
Expand Down
21 changes: 0 additions & 21 deletions ios/MyRiveView.swift

This file was deleted.

47 changes: 47 additions & 0 deletions ios/RiveReactNativeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import UIKit
import RiveRuntime

class RiveReactNativeView: UIView {
@objc var resourceName: String?
let riveView = RiveView()

override init(frame: CGRect) {
super.init(frame: frame)
riveView.frame = frame
riveView.configure(getRiveFile(resourceName: "truck_v7"), andAutoPlay: false)
addSubview(riveView)
}


override func layoutSubviews() {
super.layoutSubviews()
for view in subviews {
view.reactSetFrame(self.bounds)
}
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
fatalError("init(coder:) has not been implemented")
}

@objc func play() {
riveView.play()
}


// func updateArtboard(_ artboard: RiveArtboard) {
// self.artboard = artboard;
// }

// override func draw(_ rect: CGRect) {
// guard let context = UIGraphicsGetCurrentContext(), let artboard = self.artboard else {
// return
// }
// let renderer = RiveRenderer(context: context);
// renderer.align(with: rect, withContentRect: artboard.bounds(), with: Alignment.Center, with: Fit.Contain)
// artboard.draw(renderer)
// }

}

4 changes: 2 additions & 2 deletions ios/RiveReactNativeViewManager.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "React/RCTBridgeModule.h"
#import "RCTViewManager.h"
#import "React/RCTViewManager.h"

@interface RCT_EXTERN_MODULE(RiveReactNativeViewManager, RCTViewManager)

RCT_EXPORT_VIEW_PROPERTY(resourceName, NSString)

RCT_EXTERN_METHOD(play:(nonnull NSNumber *)node)
RCT_EXTERN_METHOD(play:(nonnull NSNumber *)node animationNames:(nonnull NSArray *)animationNames loopMode:(NSString)loopMode direction:(NSString)direction areStateMachines:(BOOL)areStateMachines)
RCT_EXTERN_METHOD(pause:(nonnull NSNumber *)node)


Expand Down
Loading

0 comments on commit 8351e67

Please sign in to comment.