Skip to content

Commit de52e6b

Browse files
committed
feat(components): allow Group to be styled
1 parent cdf72d2 commit de52e6b

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

ios/components/Group/GroupProps.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import SwiftUI
2+
3+
public final class GroupProps: ObservableObject, Decodable {
4+
@Published public var style: StyleProps?
5+
6+
enum CodingKeys: String, CodingKey {
7+
case style
8+
}
9+
10+
public required init(from decoder: Decoder) throws {
11+
let container = try decoder.container(keyedBy: CodingKeys.self)
12+
style = try container.decodeIfPresent(StyleProps.self, forKey: .style)
13+
}
14+
15+
public func merge(from other: GroupProps) {
16+
style = other.style
17+
}
18+
}

ios/components/Group/GroupView.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import SwiftUI
2+
3+
public struct GroupView<Content: View>: View {
4+
@ObservedObject public var props: GroupProps
5+
let content: () -> Content
6+
7+
public init(props: GroupProps, @ViewBuilder content: @escaping () -> Content) {
8+
self.props = props
9+
self.content = content
10+
}
11+
12+
public var body: some View {
13+
Group {
14+
content()
15+
}
16+
.applyViewStyles(props.style)
17+
}
18+
}

src/components/Group.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { type PropsWithChildren } from "react";
22
import { SwiftUIParentIdProvider } from "../contexts";
33
import { useSwiftUINode } from "../hooks";
4-
import type { FunctionComponentWithId } from "../types";
4+
import type { FunctionComponentWithId, NativeViewStyle } from "../types";
55

66
// https://developer.apple.com/documentation/swiftui/form
77

8-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
9-
export type NativeGroupProps = {};
8+
export type NativeGroupProps = {
9+
style?: NativeViewStyle;
10+
};
1011

1112
export const Group: FunctionComponentWithId<PropsWithChildren<NativeGroupProps>> = ({
1213
children,

0 commit comments

Comments
 (0)