Skip to content

Commit

Permalink
support http request in ui event dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeCla committed Nov 2, 2023
1 parent 96fad8d commit 0130d40
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions ios/Nativebrik/Nativebrik/root.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,32 @@ class ModalRootViewController: UIViewController {
self.modalViewController = modalViewController
super.init(nibName: nil, bundle: nil)

self.event = UIBlockEventManager(on: { event in
if let destPageId = event.destinationPageId {
self.presentPage(
pageId: destPageId,
props: event.payload
)
self.event = UIBlockEventManager(on: { [weak self] event in
let assertion = event.httpResponseAssertion
let handleEvent = { () -> () in
DispatchQueue.main.async { [weak self] in
if let destPageId = event.destinationPageId {
self?.presentPage(
pageId: destPageId,
props: event.payload
)
}
self?.config.dispatchUIBlockEvent(event: event)
}
}
self.config.dispatchUIBlockEvent(event: event)

if let httpRequest = event.httpRequest {
Task {
self?.repositories?.httpRequest.fetch(request: httpRequest, assertion: assertion, propeties: nil, callback: { entry in
if entry.state == .EXPECTED {
handleEvent()
}
})
}
} else {
handleEvent()
}

})

if let destId = trigger?.data?.triggerSetting?.onTrigger?.destinationPageId {
Expand Down Expand Up @@ -154,14 +172,31 @@ class RootView: UIView {
layout.isEnabled = true
}

self.event = UIBlockEventManager(on: { event in
if let destPageId = event.destinationPageId {
self.presentPage(
pageId: destPageId,
props: event.payload
)
self.event = UIBlockEventManager(on: { [weak self] event in
let assertion = event.httpResponseAssertion
let handleEvent = { () -> () in
DispatchQueue.main.async { [weak self] in
if let destPageId = event.destinationPageId {
self?.presentPage(
pageId: destPageId,
props: event.payload
)
}
self?.config.dispatchUIBlockEvent(event: event)
}
}

if let httpRequest = event.httpRequest {
Task {
self?.repositories?.httpRequest.fetch(request: httpRequest, assertion: assertion, propeties: nil, callback: { entry in
if entry.state == .EXPECTED {
handleEvent()
}
})
}
} else {
handleEvent()
}
self.config.dispatchUIBlockEvent(event: event)
})

if let destId = trigger?.data?.triggerSetting?.onTrigger?.destinationPageId {
Expand Down

0 comments on commit 0130d40

Please sign in to comment.