Skip to content

Commit

Permalink
fix interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeCla committed Jul 7, 2023
1 parent 4fc5d43 commit a972579
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ Morondava is a charming coastal town located on the western coast of Madagascar.
VStack(alignment: .leading, spacing: 0) {
Header()
ScrollView(.vertical) {
nativebrik.component(id: "ci396q223akg00audcqg").frame(width: UIScreen.main.bounds.width, height: 270)
nativebrik.component(id: "ci396q223akg00audcqg", onEvent: nil) { phase in
switch phase {
case .completed(let view):
view.frame(width: UIScreen.main.bounds.width, height: 270)
default:
Text("Loading")
}
}
ForEach(self.items, id: \.title) { item in
item.padding()
}
Expand Down
14 changes: 10 additions & 4 deletions ios/Nativebrik/Classes/component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public enum ComponentPhase {
case failure
}

class ComponentView: UIView {
class ComponentUIView: UIView {
private let componentId: String
private let config: Config
private let repositories: Repositories
Expand Down Expand Up @@ -178,12 +178,12 @@ class ComponentSwiftViewModel: ObservableObject {
switch view {
case .EUIRootBlock(let root):
self.phase = .completed(
RootViewRepresentable(
ComponentView(content: RootViewRepresentable(
root: root,
config: config,
repositories: repositories,
modalViewController: modalViewController
)
))
)
default:
self.phase = .failure
Expand All @@ -198,9 +198,15 @@ class ComponentSwiftViewModel: ObservableObject {
}
}

public struct ComponentView: View {
fileprivate let content: RootViewRepresentable
public var body: some View {
self.content
}
}
public enum AsyncComponentPhase {
case loading
case completed(any View)
case completed(ComponentView)
case failure
}
struct ComponentSwiftView: View {
Expand Down
6 changes: 3 additions & 3 deletions ios/Nativebrik/Classes/sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public class Nativebrik: ObservableObject {
}

public func componentView(id: String) -> UIView {
return ComponentView(
return ComponentUIView(
componentId: id,
config: self.config,
repositories: self.repositories,
Expand All @@ -223,7 +223,7 @@ public class Nativebrik: ObservableObject {
}

public func componentView(id: String, onEvent: ((_ event: ComponentEvent) -> Void)?) -> UIView {
return ComponentView(
return ComponentUIView(
componentId: id,
config: self.config.initFrom(onEvent: onEvent),
repositories: self.repositories,
Expand All @@ -233,7 +233,7 @@ public class Nativebrik: ObservableObject {
}

public func componentView(id: String, onEvent: ((_ event: ComponentEvent) -> Void)?, content: @escaping (_ phase: ComponentPhase) -> UIView) -> UIView {
return ComponentView(
return ComponentUIView(
componentId: id,
config: self.config.initFrom(onEvent: onEvent),
repositories: self.repositories,
Expand Down

0 comments on commit a972579

Please sign in to comment.