Skip to content

Commit 04aa25f

Browse files
committed
feat(form): add support for disabled and scrollDisabled properties in FormProps and Form components
1 parent 6f36743 commit 04aa25f

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

ios/components/Form/FormProps.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@ import SwiftUI
33

44
public final class FormProps: ObservableObject, Decodable {
55
@Published public var style: StyleProps?
6+
@Published var disabled: Bool = false
7+
@Published var scrollDisabled: Bool = false
68

79
enum CodingKeys: String, CodingKey {
810
case style
11+
case disabled
12+
case scrollDisabled
913
}
1014

1115
public required init(from decoder: Decoder) throws {
1216
let container = try decoder.container(keyedBy: CodingKeys.self)
1317
style = try container.decodeIfPresent(StyleProps.self, forKey: .style)
18+
disabled = try container.decodeIfPresent(Bool.self, forKey: .disabled) ?? false
19+
scrollDisabled = try container.decodeIfPresent(Bool.self, forKey: .scrollDisabled) ?? false
1420
}
1521

1622
public func merge(from other: FormProps) {
1723
style = other.style
24+
disabled = other.disabled
25+
scrollDisabled = other.scrollDisabled
1826
}
1927
}

ios/components/Form/FormView.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
import SwiftUI
33

44
public struct FormView<Content: View>: View {
5-
@ObservedObject public var props: FormProps
6-
let content: () -> Content
5+
@ObservedObject public var props: FormProps
6+
let content: () -> Content
77

8-
public init(props: FormProps, @ViewBuilder content: @escaping () -> Content) {
9-
self.props = props
10-
self.content = content
11-
}
8+
public init(props: FormProps, @ViewBuilder content: @escaping () -> Content) {
9+
self.props = props
10+
self.content = content
11+
}
12+
13+
public var body: some View {
14+
Form { content() }
15+
.applyViewStyles(props.style)
16+
.disabled(props.disabled)
17+
.applyFormScrollDisabled(props)
18+
}
19+
}
1220

13-
public var body: some View {
14-
Form {
15-
content()
16-
}
17-
.applyViewStyles(props.style)
21+
private extension View {
22+
@ViewBuilder
23+
func applyFormScrollDisabled(_ props: FormProps) -> some View {
24+
if #available(iOS 16, *) {
25+
self.scrollDisabled(props.scrollDisabled)
26+
} else {
27+
self
1828
}
29+
}
1930
}

src/components/Form.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { FunctionComponentWithId, NativeViewStyle } from "../types";
88

99
export type NativeFormProps = {
1010
style?: StyleProp<NativeViewStyle>;
11+
disabled?: boolean;
12+
scrollDisabled?: boolean;
1113
};
1214

1315
export const Form: FunctionComponentWithId<PropsWithChildren<NativeFormProps>> = ({

0 commit comments

Comments
 (0)