Skip to content

Commit

Permalink
Merge pull request #28 from LottieFiles/feat/interactivity-v0.1
Browse files Browse the repository at this point in the history
feat: Interactivity v0.1 integration
  • Loading branch information
samuelOsborne authored Jun 20, 2024
2 parents f350a77 + 61ceea7 commit 65befc9
Show file tree
Hide file tree
Showing 13 changed files with 1,050 additions and 20 deletions.
38 changes: 35 additions & 3 deletions Sources/DotLottie/Public/DotLottieAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ public final class DotLottieAnimation: ObservableObject {

// MARK: Playback setters / getters

public func play() {
public func play() -> Bool {
self.player.play()
}

public func pause() {
public func pause() -> Bool {
self.player.pause()
}

Expand All @@ -343,7 +343,7 @@ public final class DotLottieAnimation: ObservableObject {
- If there are no segments and direction is 1 (forward) go to start frame
- If there are segments and direction is -1 (reverse) go to end frame
*/
public func stop() {
public func stop() -> Bool {
player.stop()
}

Expand All @@ -370,6 +370,10 @@ public final class DotLottieAnimation: ObservableObject {
public func segments() -> (Float, Float) {
return (player.config().segment[0], player.config().segment[1])
}

public func setPlayerState(_ state: PlayerState) {
player.setPlayerState(state: state)
}

/// Set the current frame.
/// Can return false if the frame is invalid or equal to the current frame.
Expand Down Expand Up @@ -426,6 +430,34 @@ public final class DotLottieAnimation: ObservableObject {
return player.config().useFrameInterpolation
}

public func loadStateMachine(id: String) -> Bool {
player.loadStateMachine(id: id)
}

public func stopStateMachine() -> Bool {
player.stopStateMachine()
}

public func startStateMachine() -> Bool {
player.startStateMachine()
}

public func postEvent(_ event: Event) -> Bool {
player.postEvent(event: event)
}

public func stateMachineSubscribe(oberserver: StateMachineObserver) -> Bool {
player.stateMachineSubscribe(oberserver: oberserver)
}

public func stateMachineUnSubscribe(oberserver: StateMachineObserver) -> Bool {
player.stateMachineUnSubscribe(oberserver: oberserver)
}

public func stateMachineFrameworkSetup() -> [String] {
player.stateMachineFrameworkSetup()
}

public func setAutoplay(autoplay: Bool) {
var config = player.config()

Expand Down
48 changes: 40 additions & 8 deletions Sources/DotLottie/Public/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,26 @@ class Player: ObservableObject {
dotLottiePlayer.markers()
}

public func play() {
let _ = dotLottiePlayer.play()
public func play() -> Bool {
let play = dotLottiePlayer.play()

setPlayerState(state: .playing)
return play
}

public func pause() {
let _ = dotLottiePlayer.pause()
public func pause() -> Bool {
let pause = dotLottiePlayer.pause()

self.setPlayerState(state: .paused)

return pause
}

public func stop() {
let _ = dotLottiePlayer.stop()
public func stop() -> Bool {
let stop = dotLottiePlayer.stop()

self.setPlayerState(state: .stopped)

return stop
}

public func resize(width: Int, height: Int) throws {
Expand All @@ -205,7 +209,35 @@ class Player: ObservableObject {

return self.setFrame(no: frame)
}


public func loadStateMachine(id: String) -> Bool {
dotLottiePlayer.loadStateMachine(str: id)
}

public func startStateMachine() -> Bool {
dotLottiePlayer.startStateMachine()
}

public func stopStateMachine() -> Bool {
dotLottiePlayer.stopStateMachine()
}

public func postEvent(event: Event) -> Bool {
dotLottiePlayer.postEvent(event: event)
}

public func stateMachineSubscribe(oberserver: StateMachineObserver) -> Bool {
dotLottiePlayer.stateMachineSubscribe(observer: oberserver)
}

public func stateMachineUnSubscribe(oberserver: StateMachineObserver) -> Bool {
dotLottiePlayer.stateMachineUnsubscribe(observer: oberserver)
}

public func stateMachineFrameworkSetup() -> [String] {
dotLottiePlayer.stateMachineFrameworkSetup()
}

public func duration() -> Float32 {
return dotLottiePlayer.duration()
}
Expand Down
Loading

0 comments on commit 65befc9

Please sign in to comment.