Merge pull request #2 from rive-app/move_view

Move example view and controller to example and out of framework
This commit is contained in:
Matt Sullivan
2020-10-05 21:26:38 -07:00
committed by GitHub
13 changed files with 169 additions and 255 deletions

Binary file not shown.

View File

@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
C9696B1224FC704A0041502A /* juice.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9696B1124FC704A0041502A /* juice.riv */; };
C9696B1524FC71CE0041502A /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9696B1424FC71CE0041502A /* Utilities.swift */; };
C970484A250822F300CB3AB3 /* simple.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9704847250822F300CB3AB3 /* simple.riv */; };
C98F298B2513FD8C0076E802 /* blend.riv in Resources */ = {isa = PBXBuildFile; fileRef = C98F29882513FD8C0076E802 /* blend.riv */; };
C9927C1B250986BF009F17F5 /* truck.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9927C18250986BF009F17F5 /* truck.riv */; };
@@ -16,6 +15,8 @@
C99E2FE8251E8E35009227CA /* bird.riv in Resources */ = {isa = PBXBuildFile; fileRef = C99E2FE6251E8E35009227CA /* bird.riv */; };
C99E2FE9251E8E35009227CA /* funtime.riv in Resources */ = {isa = PBXBuildFile; fileRef = C99E2FE7251E8E35009227CA /* funtime.riv */; };
C9A7D7F52523C1D900AFB875 /* sheep.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9A7D7F22523C1D900AFB875 /* sheep.riv */; };
C9C1DF7F252BA5EF00B0A444 /* MyRiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C1DF7E252BA5EF00B0A444 /* MyRiveView.swift */; };
C9C1DF83252BA62800B0A444 /* MyRiveViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C1DF82252BA62800B0A444 /* MyRiveViewController.swift */; };
C9C73E9824FC471E00EF9516 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C73E9724FC471E00EF9516 /* AppDelegate.swift */; };
C9C73E9A24FC471E00EF9516 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C73E9924FC471E00EF9516 /* SceneDelegate.swift */; };
C9C73E9C24FC471E00EF9516 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C73E9B24FC471E00EF9516 /* ContentView.swift */; };
@@ -24,6 +25,7 @@
C9C73EA424FC471E00EF9516 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9C73EA224FC471E00EF9516 /* LaunchScreen.storyboard */; };
C9E1AA45251E957F00BD52EC /* RiveRuntime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9E1AA3E251E94CC00BD52EC /* RiveRuntime.framework */; };
C9E1AA46251E957F00BD52EC /* RiveRuntime.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C9E1AA3E251E94CC00BD52EC /* RiveRuntime.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C9EEA13125268E48001BB768 /* teeny.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9EEA12E25268E48001BB768 /* teeny.riv */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -59,7 +61,6 @@
/* Begin PBXFileReference section */
C9696B1124FC704A0041502A /* juice.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = juice.riv; sourceTree = "<group>"; };
C9696B1424FC71CE0041502A /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
C9704847250822F300CB3AB3 /* simple.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = simple.riv; sourceTree = "<group>"; };
C98F29882513FD8C0076E802 /* blend.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = blend.riv; sourceTree = "<group>"; };
C9927C18250986BF009F17F5 /* truck.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = truck.riv; sourceTree = "<group>"; };
@@ -67,6 +68,8 @@
C99E2FE6251E8E35009227CA /* bird.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = bird.riv; sourceTree = "<group>"; };
C99E2FE7251E8E35009227CA /* funtime.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = funtime.riv; sourceTree = "<group>"; };
C9A7D7F22523C1D900AFB875 /* sheep.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = sheep.riv; sourceTree = "<group>"; };
C9C1DF7E252BA5EF00B0A444 /* MyRiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRiveView.swift; sourceTree = "<group>"; };
C9C1DF82252BA62800B0A444 /* MyRiveViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRiveViewController.swift; sourceTree = "<group>"; };
C9C73E9424FC471E00EF9516 /* RiveExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RiveExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
C9C73E9724FC471E00EF9516 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C9C73E9924FC471E00EF9516 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -76,6 +79,7 @@
C9C73EA324FC471E00EF9516 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
C9C73EA524FC471E00EF9516 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C9E1AA38251E94CC00BD52EC /* RiveRuntime.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RiveRuntime.xcodeproj; path = ../RiveRuntime.xcodeproj; sourceTree = "<group>"; };
C9EEA12E25268E48001BB768 /* teeny.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = teeny.riv; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -93,6 +97,7 @@
C9696B0E24FC6FD10041502A /* Assets */ = {
isa = PBXGroup;
children = (
C9EEA12E25268E48001BB768 /* teeny.riv */,
C9A7D7F22523C1D900AFB875 /* sheep.riv */,
C99E2FE6251E8E35009227CA /* bird.riv */,
C99E2FE7251E8E35009227CA /* funtime.riv */,
@@ -105,14 +110,6 @@
path = Assets;
sourceTree = "<group>";
};
C9696B1324FC71B80041502A /* Helpers */ = {
isa = PBXGroup;
children = (
C9696B1424FC71CE0041502A /* Utilities.swift */,
);
path = Helpers;
sourceTree = "<group>";
};
C9C73E8B24FC471E00EF9516 = {
isa = PBXGroup;
children = (
@@ -135,13 +132,14 @@
C9C73E9624FC471E00EF9516 /* Source */ = {
isa = PBXGroup;
children = (
C9696B1324FC71B80041502A /* Helpers */,
C9C73E9B24FC471E00EF9516 /* ContentView.swift */,
C9C1DF7E252BA5EF00B0A444 /* MyRiveView.swift */,
C9C1DF82252BA62800B0A444 /* MyRiveViewController.swift */,
C9C73E9724FC471E00EF9516 /* AppDelegate.swift */,
C9C73E9924FC471E00EF9516 /* SceneDelegate.swift */,
C9C73E9B24FC471E00EF9516 /* ContentView.swift */,
C9C73E9D24FC471E00EF9516 /* Assets.xcassets */,
C9C73EA224FC471E00EF9516 /* LaunchScreen.storyboard */,
C9C73EA524FC471E00EF9516 /* Info.plist */,
C9C73E9D24FC471E00EF9516 /* Assets.xcassets */,
C9C73E9F24FC471E00EF9516 /* Preview Content */,
);
path = Source;
@@ -258,6 +256,7 @@
C9696B1224FC704A0041502A /* juice.riv in Resources */,
C9C73EA424FC471E00EF9516 /* LaunchScreen.storyboard in Resources */,
C99E2FE3251E8DB4009227CA /* van.riv in Resources */,
C9EEA13125268E48001BB768 /* teeny.riv in Resources */,
C99E2FE8251E8E35009227CA /* bird.riv in Resources */,
C9C73EA124FC471E00EF9516 /* Preview Assets.xcassets in Resources */,
C970484A250822F300CB3AB3 /* simple.riv in Resources */,
@@ -276,7 +275,8 @@
files = (
C9C73E9824FC471E00EF9516 /* AppDelegate.swift in Sources */,
C9C73E9A24FC471E00EF9516 /* SceneDelegate.swift in Sources */,
C9696B1524FC71CE0041502A /* Utilities.swift in Sources */,
C9C1DF7F252BA5EF00B0A444 /* MyRiveView.swift in Sources */,
C9C1DF83252BA62800B0A444 /* MyRiveViewController.swift in Sources */,
C9C73E9C24FC471E00EF9516 /* ContentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -16,9 +16,9 @@ struct ContentView: View {
}
struct MyRive: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> RiveViewController {
return RiveViewController(resource: "truck", withExtension: "riv")
func makeUIViewController(context: Context) -> MyRiveViewController {
return MyRiveViewController(withResource: "truck", withExtension: "riv")
}
func updateUIViewController(_ uiViewController: RiveViewController, context: Context) {}
func updateUIViewController(_ uiViewController: MyRiveViewController, context: Context) {}
}

View File

@@ -1,31 +0,0 @@
//
// Utilities.swift
// RiveExample
//
// Created by Matt Sullivan on 8/30/20.
// Copyright © 2020 Rive. All rights reserved.
//
import Foundation
func loadBytesFromFile(forResource res: String, withExtension ext: String) -> Data?
{
guard let fileURL = Bundle.main.url(forResource: res, withExtension: ext) else {
print("Failed to create URL for file.")
return nil
}
do {
let data = try Data(contentsOf: fileURL)
return data
}
catch {
print("Error opening file: \(error)")
return nil
}
}
extension Data {
var bytes : [UInt8]{
return [UInt8](self)
}
}

View File

@@ -0,0 +1,28 @@
//
// MyViewView.swift
// RiveExample
//
// Created by Matt Sullivan on 10/5/20.
// Copyright © 2020 Rive. All rights reserved.
//
import UIKit
import RiveRuntime
class MyRiveView: UIView {
var artboard: RiveArtboard?;
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)
}
}

View File

@@ -0,0 +1,122 @@
//
// MyRiveViewController.swift
// RiveExample
//
// Created by Matt Sullivan on 10/5/20.
// Copyright © 2020 Rive. All rights reserved.
//
import UIKit
import RiveRuntime
class MyRiveViewController: UIViewController {
var resourceName: String?
var resourceExt: String?
var artboard: RiveArtboard?
var instance: RiveLinearAnimationInstance?
var displayLink: CADisplayLink?
var lastTime: CFTimeInterval = 0
init(withResource name: String, withExtension: String) {
resourceName = name
resourceExt = withExtension
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
startRive()
}
override func loadView() {
// Wire up an instance of MyRiveView to the controller
let view = MyRiveView()
view.backgroundColor = UIColor.blue
self.view = view
}
func startRive() {
guard let name = resourceName, let ext = resourceExt else {
fatalError("No resource or extension name specified")
}
guard let url = Bundle.main.url(forResource: name, withExtension: ext) else {
fatalError("Failed to locate \(name) in bundle.")
}
guard var data = try? Data(contentsOf: url) else {
fatalError("Failed to load \(url) from bundle.")
}
// Import the data into a RiveFile
let riveFile = RiveFile()
let bytes = [UInt8](data)
data.withUnsafeMutableBytes {(mutableBytes: UnsafeMutablePointer<UInt8>) in
let importResult = RiveFile.import(mutableBytes, bytesLength: UInt64(bytes.count), to: riveFile)
if (importResult != ImportResult.success) {
fatalError("Failed to import \(url).")
}
let artboard = riveFile.artboard()
self.artboard = artboard
// update the artboard in the view
(self.view as! MyRiveView).updateArtboard(artboard)
if (artboard.animationCount() == 0) {
fatalError("No animations in the file.")
}
// Fetch the animation and draw a first frame
let animation = artboard.animation(at: 0)
let instance = animation.instance()
self.instance = instance
instance.advance(by: 0)
instance.apply(to: artboard)
artboard.advance(by: 0)
// Run the looping timer
runTimer()
}
}
// Starts the animation timer
func runTimer() {
displayLink = CADisplayLink(target: self, selector: #selector(tick));
displayLink?.add(to: .main, forMode: .default)
}
// Stops the animation timer
func stopTimer() {
displayLink?.remove(from: .main, forMode: .default)
}
// Animates a frame
@objc func tick() {
guard let displayLink = displayLink, let artboard = artboard else {
// Something's gone wrong, clean up and bug out
stopTimer()
return
}
let timestamp = displayLink.timestamp
// last time needs to be set on the first tick
if (lastTime == 0) {
lastTime = timestamp
}
// Calculate the time elapsed between ticks
let elapsedTime = timestamp - lastTime;
lastTime = timestamp;
// Advance the animation instance and the artboard
instance?.advance(by: elapsedTime) // advance the animation
instance?.apply(to: artboard) // apply to the artboard
artboard.advance(by: elapsedTime) // advance the artboard
// Trigger a redraw
self.view.setNeedsDisplay()
}
}

View File

@@ -7,10 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
C9601F23250C143A0032AA07 /* RiveViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C9601F21250C143A0032AA07 /* RiveViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
C9601F24250C143A0032AA07 /* RiveViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9601F22250C143A0032AA07 /* RiveViewController.mm */; };
C9601F27250C14560032AA07 /* RiveView.h in Headers */ = {isa = PBXBuildFile; fileRef = C9601F25250C14560032AA07 /* RiveView.h */; settings = {ATTRIBUTES = (Public, ); }; };
C9601F28250C14560032AA07 /* RiveView.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9601F26250C14560032AA07 /* RiveView.mm */; };
C9601F2B250C25930032AA07 /* RiveRenderer.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9601F2A250C25930032AA07 /* RiveRenderer.mm */; };
C9601F69251004780032AA07 /* vec2d.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C9601F2D251004770032AA07 /* vec2d.hpp */; };
C9601F6C251004780032AA07 /* color.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C9601F30251004770032AA07 /* color.hpp */; };
@@ -50,7 +46,6 @@
C9601FB6251004950032AA07 /* color.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9601FAA251004950032AA07 /* color.cpp */; };
C9601FB9251004950032AA07 /* gradient_stop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9601FAD251004950032AA07 /* gradient_stop.cpp */; };
C9601FBA251004950032AA07 /* stroke.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9601FAE251004950032AA07 /* stroke.cpp */; };
C960285B251FD59800704818 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C960285A251FD59800704818 /* UIKit.framework */; };
C98F296F2513FA8B0076E802 /* keyframe_id.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C98F296E2513FA8B0076E802 /* keyframe_id.hpp */; };
C98F29782513FAAE0076E802 /* draw_rules.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C98F29722513FAAE0076E802 /* draw_rules.hpp */; };
C98F29792513FAAE0076E802 /* draw_target_base.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C98F29732513FAAE0076E802 /* draw_target_base.hpp */; };
@@ -226,10 +221,6 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
C9601F21250C143A0032AA07 /* RiveViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RiveViewController.h; sourceTree = "<group>"; };
C9601F22250C143A0032AA07 /* RiveViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RiveViewController.mm; sourceTree = "<group>"; };
C9601F25250C14560032AA07 /* RiveView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RiveView.h; sourceTree = "<group>"; };
C9601F26250C14560032AA07 /* RiveView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RiveView.mm; sourceTree = "<group>"; };
C9601F29250C25830032AA07 /* RiveRenderer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RiveRenderer.hpp; sourceTree = "<group>"; };
C9601F2A250C25930032AA07 /* RiveRenderer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RiveRenderer.mm; sourceTree = "<group>"; };
C9601F2D251004770032AA07 /* vec2d.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = vec2d.hpp; sourceTree = "<group>"; };
@@ -301,7 +292,6 @@
C9601FAC251004950032AA07 /* shape_paint_mutator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shape_paint_mutator.cpp; sourceTree = "<group>"; };
C9601FAD251004950032AA07 /* gradient_stop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gradient_stop.cpp; sourceTree = "<group>"; };
C9601FAE251004950032AA07 /* stroke.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stroke.cpp; sourceTree = "<group>"; };
C960285A251FD59800704818 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/iOSSupport/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
C98F296E2513FA8B0076E802 /* keyframe_id.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = keyframe_id.hpp; sourceTree = "<group>"; };
C98F29722513FAAE0076E802 /* draw_rules.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = draw_rules.hpp; sourceTree = "<group>"; };
C98F29732513FAAE0076E802 /* draw_target_base.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = draw_target_base.hpp; path = generated/draw_target_base.hpp; sourceTree = "<group>"; };
@@ -507,7 +497,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C960285B251FD59800704818 /* UIKit.framework in Frameworks */,
C9D60DAC2512B04B00AAA3A6 /* QuartzCore.framework in Frameworks */,
C9D60DAA2512B01600AAA3A6 /* CoreGraphics.framework in Frameworks */,
);
@@ -650,10 +639,6 @@
C9C741F324FC510200EF9516 /* Rive.mm */,
C9601F29250C25830032AA07 /* RiveRenderer.hpp */,
C9601F2A250C25930032AA07 /* RiveRenderer.mm */,
C9601F25250C14560032AA07 /* RiveView.h */,
C9601F26250C14560032AA07 /* RiveView.mm */,
C9601F21250C143A0032AA07 /* RiveViewController.h */,
C9601F22250C143A0032AA07 /* RiveViewController.mm */,
C9C73ED424FC478800EF9516 /* RiveRuntime.h */,
C9C73ED524FC478800EF9516 /* Info.plist */,
);
@@ -1048,7 +1033,6 @@
C9D60DA62512AFE900AAA3A6 /* Frameworks */ = {
isa = PBXGroup;
children = (
C960285A251FD59800704818 /* UIKit.framework */,
C9D60DAB2512B04B00AAA3A6 /* QuartzCore.framework */,
C9D60DA92512B01600AAA3A6 /* CoreGraphics.framework */,
);
@@ -1066,8 +1050,6 @@
C9C741D224FC4F0500EF9516 /* points_path.hpp in Headers */,
C9C741F424FC510200EF9516 /* Rive.h in Headers */,
C9601F8E251004780032AA07 /* solid_color.hpp in Headers */,
C9601F27250C14560032AA07 /* RiveView.h in Headers */,
C9601F23250C143A0032AA07 /* RiveViewController.h in Headers */,
C9C741DF24FC4F0500EF9516 /* artboard.hpp in Headers */,
C9601F7F251004780032AA07 /* linear_gradient.hpp in Headers */,
C9C741B324FC4F0500EF9516 /* linear_animation.hpp in Headers */,
@@ -1332,7 +1314,6 @@
C9C7415524FC4F0500EF9516 /* cubic_asymmetric_vertex.cpp in Sources */,
C98F29842513FAC30076E802 /* keyframe_id.cpp in Sources */,
C9C7416824FC4F0500EF9516 /* file.cpp in Sources */,
C9601F28250C14560032AA07 /* RiveView.mm in Sources */,
C9C7415F24FC4F0500EF9516 /* shape_paint_container.cpp in Sources */,
C9C7413C24FC4F0500EF9516 /* binary_reader.cpp in Sources */,
C9C7416D24FC4F0500EF9516 /* skin.cpp in Sources */,
@@ -1344,7 +1325,6 @@
C98F29832513FAC30076E802 /* draw_target.cpp in Sources */,
C9C7414524FC4F0500EF9516 /* keyframe_double.cpp in Sources */,
C9C7415C24FC4F0500EF9516 /* rectangle.cpp in Sources */,
C9601F24250C143A0032AA07 /* RiveViewController.mm in Sources */,
C9C7413D24FC4F0500EF9516 /* transform_component.cpp in Sources */,
C9C7414224FC4F0500EF9516 /* keyed_object.cpp in Sources */,
C9C7416C24FC4F0500EF9516 /* weight.cpp in Sources */,

View File

@@ -16,5 +16,3 @@ FOUNDATION_EXPORT const unsigned char RiveRuntimeVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <RiveRuntime/PublicHeader.h>
#import <RiveRuntime/Rive.h>
#import <RiveRuntime/RiveView.h>
#import <RiveRuntime/RiveViewController.h>

View File

@@ -1,20 +0,0 @@
//
// RiveView.h
// RiveRuntime
//
// Created by Matt Sullivan on 9/11/20.
// Copyright © 2020 Rive. All rights reserved.
//
#import "Rive.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RiveView : UIView
- (void)updateArtboard:(RiveArtboard*)artboard;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,30 +0,0 @@
//
// RiveView.m
// RiveRuntime
//
// Created by Matt Sullivan on 9/11/20.
// Copyright © 2020 Rive. All rights reserved.
//
#import "RiveView.h"
#import "RiveRenderer.hpp"
@interface RiveView()
@end
@implementation RiveView
RiveArtboard *riveArtboard;
- (void)drawRect:(CGRect)rect {
RiveRenderer *renderer = [[RiveRenderer alloc] initWithContext:UIGraphicsGetCurrentContext()];
[renderer alignWithRect:rect withContentRect:[riveArtboard bounds] withAlignment:Alignment::Center withFit:Fit::Contain];
[riveArtboard draw:renderer];
}
- (void)updateArtboard:(RiveArtboard *)artboard {
riveArtboard = artboard;
}
@end

View File

@@ -1,19 +0,0 @@
//
// RiveViewController.h
// RiveRuntime
//
// Created by Matt Sullivan on 9/11/20.
// Copyright © 2020 Rive. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RiveViewController : UIViewController
-(instancetype)initWithResource:(NSString *)resource withExtension:(NSString *)extension;
@end
NS_ASSUME_NONNULL_END

View File

@@ -1,114 +0,0 @@
//
// RiveViewController.m
// RiveRuntime
//
// Created by Matt Sullivan on 9/11/20.
// Copyright © 2020 Rive. All rights reserved.
//
#import "Rive.h"
#import "RiveViewController.h"
#import "RiveView.h"
@implementation RiveViewController
NSString *_resource;
NSString *_extension;
RiveArtboard *artboard;
RiveLinearAnimationInstance *_instance;
CADisplayLink *displayLink = NULL;
CFTimeInterval lastTime = .0;
- (instancetype)initWithResource:(NSString *) resource withExtension:(NSString *)extension {
if (self = [super init]) {
_resource = resource;
_extension = extension;
return self;
} else {
return nil;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self forResource:_resource withExtension:_extension];
}
- (void) loadView {
RiveView *riveView = [[RiveView alloc] init];
[riveView setBackgroundColor:[UIColor blueColor]];
self.view = riveView;
}
- (void) forResource: (NSString *) resource withExtension: (NSString *) extension {
// load the Rive data
NSString *filepath = [[NSBundle mainBundle] pathForResource:resource ofType:extension];
NSError *error;
NSData* data = [NSData dataWithContentsOfFile:filepath options:NSDataReadingUncached error:&error];
// initialize the Rive file
RiveFile* riveFile = [[RiveFile alloc] init];
UInt8 *bytes = (UInt8 *) data.bytes;
ImportResult result = [RiveFile import:bytes bytesLength:data.length toFile:riveFile];
if (result != 0) {
NSLog(@"Unable to import file: result code %i", (uint)result);
return;
}
artboard = [riveFile artboard];
// update the artboard in the view
[(RiveView *)self.view updateArtboard: artboard];
NSInteger animationCount = [artboard animationCount];
// NSLog(@"Animation count: %d", (uint)animationcount);
if (animationCount > 0) {
RiveAnimation *animation = [artboard animationAt: 0];
// NSLog(@"Animation name: %@", [animation name]);
_instance = [animation instance];
[_instance advanceBy:.0]; // advance the animation
[_instance applyTo:artboard]; // apply to the artboard
[artboard advanceBy:.0]; // advance the artboard
[self runTimer];
}
}
-(void) runTimer {
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
-(void) stopTimer {
if (displayLink != NULL) {
[displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
}
-(void) tick {
if (displayLink == NULL) {
// Something's gone wrong, clean up and bug out
[self stopTimer];
}
double timestamp = [displayLink timestamp];
// Last time needs to be set on the first tick
if (lastTime == 0) {
lastTime = timestamp;
}
// Calculate the time elapsed between ticks
double elapsedTime = timestamp - lastTime;
lastTime = timestamp;
// NSLog(@"Timestamp: %.1f, elapsed time: %.5f, framerate %.1f", [displayLink timestamp], elapsedTime, 1. / elapsedTime);
[_instance advanceBy:elapsedTime]; // advance the animation
[_instance applyTo:artboard]; // apply to the artboard
[artboard advanceBy:elapsedTime]; // advance the artboard
[self.view setNeedsDisplay];
}
@end