Swift
-
[TCA] ScrollToTopSwift/TCA 2023. 12. 24. 21:39
struct ContentView: View { @State var store = Store(initialState: Content.State()) { Content() } var body: some View { WithViewStore(store, observe: { $0 }) { viewStore in VStack(spacing: 0) { ScrollViewReader(content: { proxy in ScrollView { LazyVStack { Color.clear.frame(height: 0) .id("Top") ForEach(viewStore.items, id: \.self) { int in Text(String(int)) .frame(height: 80) } } } .onReceive(st..
-
[TCA] Throttle, DebounceSwift/TCA 2023. 12. 24. 00:29
struct ContentView: View { @State var store = Store(initialState: Content.State()) { Content() } @FocusState var focused: Content.FocusItem? var body: some View { WithViewStore(store, observe: { $0 }) { viewStore in VStack { TextFieldComponent( text: viewStore.$text1, placeholder: "Placeholder" ) .focused($focused, equals: .text1) TextFieldComponent( text: viewStore.$text2, placeholder: "Placeho..
-
[SwiftUI] GlobalSpinnerSwift/SwiftUI 2023. 12. 5. 05:08
public class Spinner { private var scene: UIWindowScene? { UIApplication .shared .connectedScenes .first as? UIWindowScene } private var root: UIViewController? { scene? .keyWindow? .rootViewController } private var activityIndicator: UIActivityIndicatorView? @MainActor public func start( _ style: UIActivityIndicatorView.Style = .medium, color: UIColor = .gray ) { if self.activityIndicator == ni..
-
[SwiftUI] NavigationStackSwift/SwiftUI 2023. 11. 26. 12:28
import SwiftUI struct ContentView: View { @State var destination: Destination? var body: some View { NavigationStack { Button("Append") { destination = .detail } .navigationDestination(item: $destination, destination: { destination in switch destination { case .detail: Color.green case .setting: Color.red } }) } } } enum Destination { case detail case setting } #Preview { ContentView() }
-
[UIKit] BottomButton Keyboard + Combine + SnapKitSwift/UIKit 2023. 11. 5. 00:54
import SnapKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() hideKeyboardWhenTappedAround() NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification) .receive(on: DispatchQueue.main) .sink { notification in let info = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue let keyboardHeight = info?.cgRect..