Skip to content

Commit a651758

Browse files
author
Vitor Silveira
committed
#188: Add .automatic case, remove unused variables, and apply minor adjustments
1 parent e5b7789 commit a651758

File tree

10 files changed

+19
-17
lines changed

10 files changed

+19
-17
lines changed

Examples/Sources/NotesExample/ContentView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ struct ContentView: View {
142142
.padding()
143143
.background(textEditorBackground)
144144
.cornerRadius(4)
145-
.scrollDismissesKeyboard(.interactively)
146145
}
147146
}
148147
.padding()

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,7 @@ public final class AppKitBackend: AppBackend {
861861
return scrollView
862862
}
863863

864-
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {
865-
let scrollView = scrollView as! NSScrollView
866-
}
864+
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {}
867865

868866
public func setScrollBarPresence(
869867
ofScrollContainer scrollView: Widget,

Sources/Gtk3Backend/Gtk3Backend.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,7 @@ public final class Gtk3Backend: AppBackend {
539539
return scrollView
540540
}
541541

542-
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {
543-
let scrollView = scrollView as! ScrolledWindow
544-
}
542+
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {}
545543

546544
public func setScrollBarPresence(
547545
ofScrollContainer scrollView: Widget,

Sources/GtkBackend/GtkBackend.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,7 @@ public final class GtkBackend: AppBackend {
503503
return scrollView
504504
}
505505

506-
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {
507-
let scrollView = scrollView as! ScrolledWindow
508-
}
506+
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {}
509507

510508
public func setScrollBarPresence(
511509
ofScrollContainer scrollView: Widget,

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ public protocol AppBackend {
268268
///
269269
/// This method is primarily used on iOS to apply environment changes
270270
/// that affect the scroll view’s behavior, such as keyboard dismissal mode.
271-
/// It allows the backend to update UIKit-specific properties (e.g. `keyboardDismissMode`)
272-
/// when the environment changes.
273271
///
274272
/// - Parameters:
275273
/// - scrollView: The scroll container widget previously created by `createScrollContainer(for:)`.

Sources/SwiftCrossUI/Environment/EnvironmentValues.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public struct EnvironmentValues {
7777

7878
/// Whether user interaction is enabled. Set by ``View/disabled(_:)``.
7979
public var isEnabled: Bool
80-
80+
81+
/// The way that scrollable content interacts with the software keyboard.
8182
public var scrollDismissesKeyboardMode: ScrollDismissesKeyboardMode
8283

8384
/// Called by view graph nodes when they resize due to an internal state
@@ -198,7 +199,7 @@ public struct EnvironmentValues {
198199
listStyle = .default
199200
toggleStyle = .button
200201
isEnabled = true
201-
scrollDismissesKeyboardMode = .interactively
202+
scrollDismissesKeyboardMode = .automatic
202203
}
203204

204205
/// Returns a copy of the environment with the specified property set to the

Sources/SwiftCrossUI/Values/ScrollDismissesKeyboardMode.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
/// Use this type in a call to the ``View/scrollDismissesKeyboard(_:)``
44
/// modifier to specify the dismissal behavior of scrollable views.
55
public enum ScrollDismissesKeyboardMode: Sendable {
6+
/// Determine the mode automatically based on the surrounding context.
7+
///
8+
/// Currently, this behaves the same as ``ScrollDismissesKeyboardMode/interactively``.
9+
/// In the future, it may adapt dynamically based on the context, similar to how
10+
/// SwiftUI's `.automatic` works (e.g., using `.interactively` in some views and
11+
/// `.immediately` in others). Using this value avoids source-breaking changes later on.
12+
case automatic
13+
614
/// Dismiss the keyboard as soon as scrolling starts.
715
case immediately
816

Sources/UIKitBackend/UIKitBackend+Container.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ final class ScrollWidget: ContainerWidget {
6060
public func updateScrollContainer(environment: EnvironmentValues) {
6161
#if os(iOS)
6262
scrollView.keyboardDismissMode = switch environment.scrollDismissesKeyboardMode {
63+
case .automatic:
64+
.interactive
6365
case .immediately:
6466
.onDrag
6567
case .interactively:

Sources/UIKitBackend/UIKitBackend+Control.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ extension UIKitBackend {
320320

321321
textEditorWidget.child.alwaysBounceVertical = environment.scrollDismissesKeyboardMode != .never
322322
textEditorWidget.child.keyboardDismissMode = switch environment.scrollDismissesKeyboardMode {
323+
case .automatic:
324+
textEditorWidget.child.inputAccessoryView == nil ? .interactive : .interactiveWithAccessory
323325
case .immediately:
324326
textEditorWidget.child.inputAccessoryView == nil ? .onDrag : .onDragWithAccessory
325327
case .interactively:

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ public final class WinUIBackend: AppBackend {
616616
return scrollViewer
617617
}
618618

619-
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {
620-
let scrollView = scrollView as! WinUI.ScrollViewer
621-
}
619+
public func updateScrollContainer(_ scrollView: Widget, environment: EnvironmentValues) {}
622620

623621
public func setScrollBarPresence(
624622
ofScrollContainer scrollView: Widget,

0 commit comments

Comments
 (0)