Last active
January 31, 2022 21:11
-
-
Save amosgyamfi/1a5e0dac1afa89c85b411bf0607ec845 to your computer and use it in GitHub Desktop.
Use this when you want to create balloons-like screen effect for your app
This file contains hidden or 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
| // | |
| // EchoEffect.swift | |
| // iMessageClone | |
| // | |
| // Created by Amos from Stream on 18.12.2021. | |
| // | |
| import SwiftUI | |
| struct BalloonsEffect: View { | |
| @State private var messageEffect = 0 | |
| @State private var moving = false | |
| @State private var chromaRotate = false | |
| var body: some View { | |
| ZStack { | |
| if #available(iOS 15.0, *) { | |
| ZStack { | |
| Image("baloonPurple") | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .scaleEffect(0.55) | |
| .zIndex(1) | |
| .offset(y: moving ? -450 : 450) | |
| .rotationEffect(.degrees(moving ? -5 : 5), anchor: moving ? .bottomLeading : .bottom) | |
| Image("baloonGreen") | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .scaleEffect(0.25) | |
| .zIndex(4) | |
| .offset(y: moving ? -460 : 460) | |
| .rotationEffect(.degrees(moving ? -15 : 15), anchor: moving ? .bottom : .trailing) | |
| Image("baloonOrangeDark") | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .scaleEffect(0.5) | |
| .zIndex(3) | |
| .offset(y: moving ? -480 : 480) | |
| .rotationEffect(.degrees(moving ? 15 : -15), anchor: moving ? .bottom : .trailing) | |
| Image("baloonOrangeLight") | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .scaleEffect(0.2) | |
| .zIndex(5) | |
| .offset(y: moving ? -480 : 480) | |
| .rotationEffect(.degrees(moving ? -45 : 15), anchor: moving ? .trailing: .leading) | |
| Image("baloonRed") | |
| .resizable() | |
| .aspectRatio(contentMode: .fit) | |
| .scaleEffect(0.5) | |
| .zIndex(2) | |
| .offset(y: moving ? -600 : 600) | |
| .rotationEffect(.degrees(moving ? 0 : -90), anchor: moving ? .topLeading: .trailing) | |
| } | |
| .blendMode(.screen) | |
| //.hueRotation(.degrees(chromaRotate ? 0 : 200)) | |
| .task { | |
| withAnimation(.easeInOut(duration: 6).repeatForever(autoreverses: false)){ | |
| moving.toggle() | |
| chromaRotate.toggle() | |
| } | |
| } | |
| } else { | |
| // Fallback on earlier versions | |
| } | |
| HStack { | |
| Spacer() | |
| Text("Send with balloons") | |
| .font(.caption) | |
| .textCase(.uppercase) | |
| } | |
| .frame(width: 330) | |
| } | |
| } | |
| } | |
| struct BalloonsEffect_Previews: PreviewProvider { | |
| static var previews: some View { | |
| BalloonsEffect() | |
| .preferredColorScheme(.dark) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment