Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bac1314 committed Aug 30, 2024
1 parent 1bbac95 commit 0270d38
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ struct AudioCallKitView: View {
}
.navigationDestination(for: String.self) { value in
if value == CallState.incall.rawValue {
InCallAudioView(path: $path)
.environmentObject(agoraVM)
InCallAudioView(agoraVM: agoraVM, path: $path)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import SwiftUI
import Foundation

struct InCallAudioView: View {
// @Environment(\.presentationMode) var mode: Binding<PresentationMode> // For the custom back button
@EnvironmentObject var agoraVM: AudioCallKitViewModel
@ObservedObject var agoraVM: AudioCallKitViewModel
@Binding var path: NavigationPath

let columns: [GridItem] = [
Expand Down Expand Up @@ -129,6 +128,5 @@ struct InCallAudioView: View {
}

#Preview {
InCallAudioView(path: .constant(NavigationPath()))
.environmentObject(AudioCallKitViewModel())
InCallAudioView(agoraVM: AudioCallKitViewModel(), path: .constant(NavigationPath()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct GoBoardView: View {
@EnvironmentObject var agoraRTMVM: MiniGoViewModel
@ObservedObject var agoraRTMVM: MiniGoViewModel
@State var cellSize : CGFloat = 30
@State var virtualIndex = 0
var virtualgifts : [String] = [
Expand Down Expand Up @@ -370,8 +370,7 @@ struct GoBoardView: View {
}

#Preview {
GoBoardView()
.environmentObject(MiniGoViewModel())
GoBoardView(agoraRTMVM: MiniGoViewModel())
}

extension AnyTransition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ struct MiniGoView: View {
if agoraRTMVM.isLoggedIn {
VStack {
Spacer()
GoBoardView()
.environmentObject(agoraRTMVM)
GoBoardView(agoraRTMVM: agoraRTMVM)
Spacer()
Text("Logged in as \(agoraRTMVM.userID)")
.font(.caption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ struct MiniTicTacToeView: View {

// MARK: Display TicTacToe Board
if agoraRTMVM.isLoggedIn {
TicTacToeBoardView()
.environmentObject(agoraRTMVM)
TicTacToeBoardView(agoraRTMVM: agoraRTMVM)
}

// MARK: SHOW CUSTOM ALERT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct TicTacToeBoardView: View {

@EnvironmentObject var agoraRTMVM: MiniTicTacToeViewModel
@ObservedObject var agoraRTMVM: MiniTicTacToeViewModel
@State var virtualIndex = 0
var virtualgifts : [String] = [
"flower1", "flowers2", "present", "fireworks1"
Expand Down Expand Up @@ -298,6 +298,5 @@ struct TicTacToeBoardView: View {


#Preview {
TicTacToeBoardView()
.environmentObject(MiniTicTacToeViewModel())
TicTacToeBoardView(agoraRTMVM: MiniTicTacToeViewModel())
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ struct ChannelMessagingView: View {
.navigationDestination(for: CustomChildNavType.self) { value in
switch value {
case .ChannelMessagingDetailedView(let selectedChannel):
ChannelMessagingDetailedView(selectedChannel: selectedChannel, path: $path)
.environmentObject(agoraRTMVM)
ChannelMessagingDetailedView(agoraRTMVM: agoraRTMVM, selectedChannel: selectedChannel, path: $path)
default:
Text("ChannelMessagingView Not found")
}
Expand All @@ -166,7 +165,7 @@ struct ChannelMessagingView: View {

// MARK: TO SHOW THE LIST OF MESSAGES OF SPECIFIED CHANNEL
struct ChannelMessagingDetailedView: View {
@EnvironmentObject var agoraRTMVM: ChannelMessagingViewModel
@ObservedObject var agoraRTMVM: ChannelMessagingViewModel
@FocusState private var keyboardIsFocused: Bool
@State var selectedChannel: String = ""
@State var newMessage: String = ""
Expand Down Expand Up @@ -299,9 +298,5 @@ struct ChannelMessagingDetailedView: View {


#Preview {
ChannelMessagingView(path: .constant(NavigationPath()))
.environmentObject(ChannelMessagingViewModel())

// ChannelMessagingDetailedView(path: .constant(NavigationPath()))
// .environmentObject(ChannelMessagingViewModel())
ChannelMessagingView(agoraRTMVM: ChannelMessagingViewModel() ,path: .constant(NavigationPath()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ struct P2PMessagingView: View {
.navigationDestination(for: CustomChildNavType.self) { value in
switch value {
case .P2PMessagingDetailedView(let selectedUser):
P2PMessagingDetailedView(selectedUser: selectedUser, path: $path)
.environmentObject(agoraRTMVM)
P2PMessagingDetailedView(agoraRTMVM: agoraRTMVM, selectedUser: selectedUser, path: $path)
default:
Text("ChannelMessagingView Not found")
}
Expand All @@ -152,14 +151,12 @@ struct P2PMessagingView: View {

#Preview {
P2PMessagingView(path: .constant(NavigationPath()))
.environmentObject(P2PMessagingViewModel())

}


// MARK: TO SHOW THE LIST OF MESSAGES OF SPECIFIED CHANNEL
struct P2PMessagingDetailedView: View {
@EnvironmentObject var agoraRTMVM: P2PMessagingViewModel
@ObservedObject var agoraRTMVM: P2PMessagingViewModel
@FocusState private var keyboardIsFocused: Bool
@State var selectedUser: String = ""
@State var message: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ struct StreamMessagingView: View {
.navigationDestination(for: CustomChildNavType.self) { value in
switch value {
case .StreamMessagingDetailedView(let selectedTopic):
StreamMessagingDetailedView(selectedTopic: selectedTopic, path: $path)
.environmentObject(agoraRTMVM)
StreamMessagingDetailedView(agoraRTMVM: agoraRTMVM, selectedTopic: selectedTopic, path: $path)
default:
Text("ChannelMessagingView Not found")
}
Expand All @@ -153,7 +152,7 @@ struct StreamMessagingView: View {

// MARK: TO SHOW THE LIST OF MESSAGES OF SPECIFIED CHANNEL
struct StreamMessagingDetailedView: View {
@EnvironmentObject var agoraRTMVM: StreamMessagingViewModel
@ObservedObject var agoraRTMVM: StreamMessagingViewModel
@FocusState private var keyboardIsFocused: Bool
@State var selectedTopic: String = ""
@State var message: String = ""
Expand Down Expand Up @@ -219,7 +218,6 @@ struct StreamMessagingDetailedView: View {


#Preview {
StreamMessagingDetailedView(path: .constant(NavigationPath()))
.environmentObject(StreamMessagingViewModel())
StreamMessagingDetailedView(agoraRTMVM: StreamMessagingViewModel(), path: .constant(NavigationPath()))
}

1 change: 0 additions & 1 deletion APIExample_RTM2x/Examples/LoginRTMView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SwiftUI


struct LoginRTMView: View {
// @EnvironmentObject var agoraRTMVM: AgoraRTMViewModel
@Binding var isLoading: Bool
@Binding var userID: String
@Binding var token: String
Expand Down
36 changes: 15 additions & 21 deletions APIExample_RTM2x/TestingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,22 @@ import SwiftUI
import AVFoundation

struct TestingView: View {
let items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@State private var scale: CGFloat = 0.1 // Start small
@State private var offset: CGSize = CGSize(width: UIScreen.main.bounds.width, height: 0) // Offset to the top right

var body: some View {
NavigationView {
List(items, id: \.self) { item in
Text(item)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
.padding(.vertical, 5) // Adds spacing between items
.onTapGesture {

print("Hello World \(item)")
}


}
.listStyle(.plain)
.navigationTitle("Items List")
}
}
var body: some View {
Rectangle()
.fill(Color.blue) // Change to your desired color or view
.scaleEffect(scale, anchor: .topTrailing) // Scale from the top right
.offset(x: offset.width, y: offset.height) // Initial offset
.onAppear {
withAnimation(.easeInOut(duration: 0.5)) {
scale = 1.0 // Scale to full size
offset = CGSize.zero // Reset offset
}
}
.edgesIgnoringSafeArea(.all) // Make sure it fills the entire screen
}
}


Expand Down

0 comments on commit 0270d38

Please sign in to comment.