generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #409 from School-of-Company/395-add-search-post-co…
…de-feature 🔀 :: [#395] 강의 장소 우편번호 검색 기능 추가
- Loading branch information
Showing
8 changed files
with
181 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...rces/Feature/LectureDetailSettingFeature/Sources/Component/View/LectureLocationView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import SwiftUI | ||
|
||
struct LectureLocationView: View { | ||
@Binding var isShowingPostCodeSheet: Bool | ||
@Binding var address: String | ||
@Binding var locationDetail: String | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 8) { | ||
BitgouelText( | ||
text: "강의 장소", | ||
font: .text1 | ||
) | ||
|
||
PickerTextField( | ||
"지번, 도로명 주소 검색", | ||
text: address | ||
) { | ||
isShowingPostCodeSheet = true | ||
} | ||
|
||
BitgouelTextField( | ||
"상세 주소 입력", | ||
text: $locationDetail | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import SwiftUI | ||
import WebKit | ||
|
||
struct KakaoPostCodeView: UIViewRepresentable { | ||
let request: URLRequest | ||
var webView: WKWebView? | ||
@Binding var isShowingKakaoWebSheet: Bool | ||
@Binding var address: String | ||
|
||
init( | ||
request: URLRequest, | ||
isShowingKakaoWebSheet: Binding<Bool>, | ||
address: Binding<String> | ||
) { | ||
self.webView = WKWebView() | ||
self.request = request | ||
self._isShowingKakaoWebSheet = isShowingKakaoWebSheet | ||
self._address = address | ||
self.webView?.configuration.userContentController.add(KakaoWebController(isShowingkakaoWebSheet: _isShowingKakaoWebSheet, address: _address), name: "callBackHandler") | ||
} | ||
|
||
func makeUIView(context: Context) -> WKWebView { | ||
return webView! | ||
} | ||
|
||
func updateUIView(_ uiView: WKWebView, context: Context) { | ||
uiView.load(request) | ||
} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(parent: self) | ||
} | ||
|
||
class Coordinator: NSObject, WKNavigationDelegate { | ||
let parent: KakaoPostCodeView | ||
|
||
init(parent: KakaoPostCodeView) { | ||
self.parent = parent | ||
} | ||
} | ||
} | ||
|
||
class KakaoWebController: NSObject, WKScriptMessageHandler { | ||
@Binding var isShowingKakaoWebSheet: Bool | ||
@Binding var address: String | ||
|
||
init( | ||
isShowingkakaoWebSheet: Binding<Bool>, | ||
address: Binding<String> | ||
) { | ||
self._isShowingKakaoWebSheet = isShowingkakaoWebSheet | ||
self._address = address | ||
} | ||
|
||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { | ||
if message.name == "callBackHandler", let data = message.body as? [String: Any] { | ||
if message.name == "callBackHandler" { | ||
print("message name : \(message.name)") | ||
print("post Message : \(message.body)") | ||
|
||
if let roadAddress = (data["roadAddress"]) as? String { | ||
print("roadAddress: \(roadAddress)") | ||
address = roadAddress | ||
print(address) | ||
} | ||
isShowingKakaoWebSheet.toggle() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
extension KakaoPostCodeView { | ||
func callJS(_ args: Any = "") { | ||
webView?.evaluateJavaScript("postMessageToiOS('\(args)')") { result, error in | ||
if let error { | ||
print("Error \(error.localizedDescription)") | ||
return | ||
} | ||
|
||
if result == nil { | ||
print("It's void function") | ||
return | ||
} | ||
|
||
print("Received Data \(result ?? "")") | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters