-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SwiftUI support for loading async LottieAnimations and DotLottieF…
…iles Co-authored-by: Cal Stephens <[email protected]>
- Loading branch information
1 parent
edf0dd8
commit 5f21ab0
Showing
13 changed files
with
377 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Created by miguel_jimenez on 7/25/23. | ||
// Copyright © 2023 Airbnb Inc. All rights reserved. | ||
|
||
import Lottie | ||
import SwiftUI | ||
|
||
// MARK: - AnimationListView | ||
|
||
struct RemoteAnimationsDemoView: View { | ||
|
||
struct Item: Hashable { | ||
let name: String | ||
let url: URL | ||
} | ||
|
||
let wrapInNavStack: Bool | ||
|
||
var body: some View { | ||
if wrapInNavStack { | ||
NavigationStack { | ||
listBody | ||
} | ||
} else { | ||
listBody | ||
} | ||
} | ||
|
||
var listBody: some View { | ||
List { | ||
ForEach(items, id: \.self) { item in | ||
NavigationLink(value: item) { | ||
HStack { | ||
LottieView { | ||
await LottieAnimation.loadedFrom(url: item.url) | ||
} placeholder: { | ||
LoadingIndicator() | ||
} | ||
.currentProgress(0.5) | ||
.imageProvider(.exampleAppSampleImages) | ||
.frame(width: 50, height: 50) | ||
.padding(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8)) | ||
|
||
Text(item.name) | ||
} | ||
} | ||
.navigationDestination(for: Item.self) { item in | ||
AnimationPreviewView(animationSource: .remote(url: item.url, name: item.name)) | ||
} | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.navigationTitle("Remote Animations") | ||
} | ||
} | ||
|
||
var items: [Item] { | ||
[ | ||
Item( | ||
name: "Rooms Animation", | ||
url: URL(string: "https://a0.muscache.com/pictures/96699af6-b73e-499f-b0f5-3c862ae7d126.json")!), | ||
] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Created by Cal Stephens on 7/26/23. | ||
// Copyright © 2023 Airbnb Inc. All rights reserved. | ||
|
||
public enum LottieAnimationSource { | ||
case lottieAnimation(LottieAnimation) | ||
case dotLottieFile(DotLottieFile) | ||
|
||
/// The animation displayed by this data source | ||
var animation: LottieAnimation? { | ||
switch self { | ||
case .lottieAnimation(let animation): | ||
return animation | ||
case .dotLottieFile(let dotLottieFile): | ||
return dotLottieFile.animation()?.animation | ||
} | ||
} | ||
} |
Oops, something went wrong.