Skip to content

Commit

Permalink
Merge pull request #21 from LottieFiles/feat/layout
Browse files Browse the repository at this point in the history
feat: added layout feature
  • Loading branch information
eharrison authored Mar 14, 2024
2 parents fab830a + 2bb3c4f commit 8e19429
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Sources/DotLottie/Public/DotLottieAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public class DotLottieAnimation: ObservableObject {
speed: config.speed ?? 1.0,
useFrameInterpolation: config.useFrameInterpolation ?? false,
segments: config.segments != nil ? [config.segments!.0, config.segments!.1] : [],
backgroundColor: 0, marker: config.marker ?? "")
backgroundColor: 0,
layout: config.layout ?? createDefaultLayout(),
marker: config.marker ?? "")

self.player = Player(config: self.config)

Expand Down
3 changes: 3 additions & 0 deletions Sources/DotLottie/Public/Models/AnimationConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public struct AnimationConfig {
public var backgroundColor: CIImage? = .clear
public var width: Int? = 512
public var height: Int? = 512
public var layout: Layout? = createDefaultLayout()
public var marker: String? = ""

public init(
Expand All @@ -30,6 +31,7 @@ public struct AnimationConfig {
backgroundColor: CIImage? = .clear,
width: Int? = nil,
height: Int? = nil,
layout: Layout? = createDefaultLayout(),
marker: String? = nil
) {
self.autoplay = autoplay
Expand All @@ -41,6 +43,7 @@ public struct AnimationConfig {
self.backgroundColor = backgroundColor
self.width = width
self.height = height
self.layout = layout
self.marker = marker
}
}
141 changes: 141 additions & 0 deletions Sources/DotLottie/Public/dotlottie_player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ public struct Config {
public var useFrameInterpolation: Bool
public var segments: [Float]
public var backgroundColor: UInt32
public var layout: Layout
public var marker: String

// Default memberwise initializers are never public by default, so we
Expand All @@ -1315,6 +1316,7 @@ public struct Config {
useFrameInterpolation: Bool,
segments: [Float],
backgroundColor: UInt32,
layout: Layout,
marker: String
) {
self.autoplay = autoplay
Expand All @@ -1324,6 +1326,7 @@ public struct Config {
self.useFrameInterpolation = useFrameInterpolation
self.segments = segments
self.backgroundColor = backgroundColor
self.layout = layout
self.marker = marker
}
}
Expand Down Expand Up @@ -1351,6 +1354,9 @@ extension Config: Equatable, Hashable {
if lhs.backgroundColor != rhs.backgroundColor {
return false
}
if lhs.layout != rhs.layout {
return false
}
if lhs.marker != rhs.marker {
return false
}
Expand All @@ -1365,6 +1371,7 @@ extension Config: Equatable, Hashable {
hasher.combine(useFrameInterpolation)
hasher.combine(segments)
hasher.combine(backgroundColor)
hasher.combine(layout)
hasher.combine(marker)
}
}
Expand All @@ -1380,6 +1387,7 @@ public struct FfiConverterTypeConfig: FfiConverterRustBuffer {
useFrameInterpolation: FfiConverterBool.read(from: &buf),
segments: FfiConverterSequenceFloat.read(from: &buf),
backgroundColor: FfiConverterUInt32.read(from: &buf),
layout: FfiConverterTypeLayout.read(from: &buf),
marker: FfiConverterString.read(from: &buf)
)
}
Expand All @@ -1392,6 +1400,7 @@ public struct FfiConverterTypeConfig: FfiConverterRustBuffer {
FfiConverterBool.write(value.useFrameInterpolation, into: &buf)
FfiConverterSequenceFloat.write(value.segments, into: &buf)
FfiConverterUInt32.write(value.backgroundColor, into: &buf)
FfiConverterTypeLayout.write(value.layout, into: &buf)
FfiConverterString.write(value.marker, into: &buf)
}
}
Expand All @@ -1404,6 +1413,61 @@ public func FfiConverterTypeConfig_lower(_ value: Config) -> RustBuffer {
return FfiConverterTypeConfig.lower(value)
}

public struct Layout {
public var fit: Fit
public var align: [Float]

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(
fit: Fit,
align: [Float]
) {
self.fit = fit
self.align = align
}
}

extension Layout: Equatable, Hashable {
public static func == (lhs: Layout, rhs: Layout) -> Bool {
if lhs.fit != rhs.fit {
return false
}
if lhs.align != rhs.align {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(fit)
hasher.combine(align)
}
}

public struct FfiConverterTypeLayout: FfiConverterRustBuffer {
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Layout {
return
try Layout(
fit: FfiConverterTypeFit.read(from: &buf),
align: FfiConverterSequenceFloat.read(from: &buf)
)
}

public static func write(_ value: Layout, into buf: inout [UInt8]) {
FfiConverterTypeFit.write(value.fit, into: &buf)
FfiConverterSequenceFloat.write(value.align, into: &buf)
}
}

public func FfiConverterTypeLayout_lift(_ buf: RustBuffer) throws -> Layout {
return try FfiConverterTypeLayout.lift(buf)
}

public func FfiConverterTypeLayout_lower(_ value: Layout) -> RustBuffer {
return FfiConverterTypeLayout.lower(value)
}

public struct Manifest {
public var activeAnimationId: String?
public var animations: [ManifestAnimation]
Expand Down Expand Up @@ -1786,6 +1850,72 @@ public func FfiConverterTypeMarker_lower(_ value: Marker) -> RustBuffer {
return FfiConverterTypeMarker.lower(value)
}

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
public enum Fit {
case contain
case fill
case cover
case fitWidth
case fitHeight
case none
}

public struct FfiConverterTypeFit: FfiConverterRustBuffer {
typealias SwiftType = Fit

public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Fit {
let variant: Int32 = try readInt(&buf)
switch variant {
case 1: return .contain

case 2: return .fill

case 3: return .cover

case 4: return .fitWidth

case 5: return .fitHeight

case 6: return .none

default: throw UniffiInternalError.unexpectedEnumCase
}
}

public static func write(_ value: Fit, into buf: inout [UInt8]) {
switch value {
case .contain:
writeInt(&buf, Int32(1))

case .fill:
writeInt(&buf, Int32(2))

case .cover:
writeInt(&buf, Int32(3))

case .fitWidth:
writeInt(&buf, Int32(4))

case .fitHeight:
writeInt(&buf, Int32(5))

case .none:
writeInt(&buf, Int32(6))
}
}
}

public func FfiConverterTypeFit_lift(_ buf: RustBuffer) throws -> Fit {
return try FfiConverterTypeFit.lift(buf)
}

public func FfiConverterTypeFit_lower(_ value: Fit) -> RustBuffer {
return FfiConverterTypeFit.lower(value)
}

extension Fit: Equatable, Hashable {}

// Note that we don't yet support `indirect` for enums.
// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
public enum Mode {
Expand Down Expand Up @@ -2097,6 +2227,14 @@ private struct FfiConverterSequenceTypeMarker: FfiConverterRustBuffer {
}
}

public func createDefaultLayout() -> Layout {
return try! FfiConverterTypeLayout.lift(
try! rustCall {
uniffi_dotlottie_player_fn_func_create_default_layout($0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand All @@ -2113,6 +2251,9 @@ private var initializationResult: InitializationResult {
if bindings_contract_version != scaffolding_contract_version {
return InitializationResult.contractVersionMismatch
}
if uniffi_dotlottie_player_checksum_func_create_default_layout() != 41529 {
return InitializationResult.apiChecksumMismatch
}
if uniffi_dotlottie_player_checksum_method_dotlottieplayer_buffer_len() != 33793 {
return InitializationResult.apiChecksumMismatch
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/DotLottieCore/DotLottiePlayer.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<key>BinaryPath</key>
<string>DotLottiePlayer.framework/DotLottiePlayer</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>macos-arm64_x86_64</string>
<key>LibraryPath</key>
<string>DotLottiePlayer.framework</string>
<key>SupportedArchitectures</key>
Expand All @@ -17,15 +17,13 @@
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
<string>macos</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>DotLottiePlayer.framework/DotLottiePlayer</string>
<key>LibraryIdentifier</key>
<string>macos-arm64_x86_64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>DotLottiePlayer.framework</string>
<key>SupportedArchitectures</key>
Expand All @@ -34,7 +32,9 @@
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>macos</string>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ void uniffi_dotlottie_player_fn_method_observer_on_play(void*_Nonnull ptr, RustC
void uniffi_dotlottie_player_fn_method_observer_on_render(void*_Nonnull ptr, float frame_no, RustCallStatus *_Nonnull out_status
);
void uniffi_dotlottie_player_fn_method_observer_on_stop(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_dotlottie_player_fn_func_create_default_layout(RustCallStatus *_Nonnull out_status

);
RustBuffer ffi_dotlottie_player_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
Expand Down Expand Up @@ -258,6 +261,9 @@ void ffi_dotlottie_player_rust_future_cancel_void(void* _Nonnull handle
void ffi_dotlottie_player_rust_future_free_void(void* _Nonnull handle
);
void ffi_dotlottie_player_rust_future_complete_void(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
);
uint16_t uniffi_dotlottie_player_checksum_func_create_default_layout(void

);
uint16_t uniffi_dotlottie_player_checksum_method_dotlottieplayer_buffer_len(void

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ void uniffi_dotlottie_player_fn_method_observer_on_play(void*_Nonnull ptr, RustC
void uniffi_dotlottie_player_fn_method_observer_on_render(void*_Nonnull ptr, float frame_no, RustCallStatus *_Nonnull out_status
);
void uniffi_dotlottie_player_fn_method_observer_on_stop(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_dotlottie_player_fn_func_create_default_layout(RustCallStatus *_Nonnull out_status

);
RustBuffer ffi_dotlottie_player_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
Expand Down Expand Up @@ -258,6 +261,9 @@ void ffi_dotlottie_player_rust_future_cancel_void(void* _Nonnull handle
void ffi_dotlottie_player_rust_future_free_void(void* _Nonnull handle
);
void ffi_dotlottie_player_rust_future_complete_void(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
);
uint16_t uniffi_dotlottie_player_checksum_func_create_default_layout(void

);
uint16_t uniffi_dotlottie_player_checksum_method_dotlottieplayer_buffer_len(void

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ void uniffi_dotlottie_player_fn_method_observer_on_play(void*_Nonnull ptr, RustC
void uniffi_dotlottie_player_fn_method_observer_on_render(void*_Nonnull ptr, float frame_no, RustCallStatus *_Nonnull out_status
);
void uniffi_dotlottie_player_fn_method_observer_on_stop(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_dotlottie_player_fn_func_create_default_layout(RustCallStatus *_Nonnull out_status

);
RustBuffer ffi_dotlottie_player_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
Expand Down Expand Up @@ -258,6 +261,9 @@ void ffi_dotlottie_player_rust_future_cancel_void(void* _Nonnull handle
void ffi_dotlottie_player_rust_future_free_void(void* _Nonnull handle
);
void ffi_dotlottie_player_rust_future_complete_void(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
);
uint16_t uniffi_dotlottie_player_checksum_func_create_default_layout(void

);
uint16_t uniffi_dotlottie_player_checksum_method_dotlottieplayer_buffer_len(void

Expand Down

0 comments on commit 8e19429

Please sign in to comment.