Skip to content

Commit

Permalink
Enable localisation in Share extension
Browse files Browse the repository at this point in the history
  • Loading branch information
hartlco committed Dec 20, 2021
1 parent dfe666c commit 69dde10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 62 deletions.
63 changes: 6 additions & 57 deletions Icro-Share/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ import Client
}

private func openCompose(for viewModel: ComposeViewModel) {
let navigationController = UINavigationController(nibName: nil, bundle: nil)
let composeView = ComposeView(viewModel: viewModel)
var composeView = ComposeView(viewModel: viewModel)
composeView.didClose = { [weak self] in
self?.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}

let composeViewController = UIHostingController(rootView: composeView)
// composeViewController.didClose = { [weak self] in
// self?.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
// }
navigationController.viewControllers = [composeViewController]
add(navigationController, view: view)
add(composeViewController, view: view)
}
}

Expand All @@ -82,53 +81,3 @@ import Client
removeFromParent()
}
}

private class EmptyItemNavigator: ItemNavigatorProtocol {
func showLogin() {

}

func open(url: URL) {

}

func open(author: Author) {

}

func open(authorName: String) {

}

func openFollowing(for user: Author) {

}

func openConversation(item: Item) {

}

func openMedia(media: [Media], index: Int) {

}

func openReply(item: Item) {

}

func share(item: Item, sourceView: UIView?) {

}

func accessibilityPresentLinks(linkList: [(text: String, url: URL)], message: String, sourceView: UIView) {

}

func openMore(item: Item, sourceView: UIView?) {

}

func showDiscoveryCategories(categories: [DiscoveryCategory], sourceView: UIView) {

}
}
2 changes: 2 additions & 0 deletions Icro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
C5046551274F794A0004B812 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = C5046550274F794A0004B812 /* Kingfisher */; };
C5046553274F795A0004B812 /* Sourceful in Frameworks */ = {isa = PBXBuildFile; productRef = C5046552274F795A0004B812 /* Sourceful */; };
C51F8480267F1FFB002A018E /* Client in Frameworks */ = {isa = PBXBuildFile; productRef = C51F847F267F1FFB002A018E /* Client */; };
C527CEAE2770526F0086397A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF707E762131C45600506E64 /* Localizable.strings */; };
C5282B932764AC47004F5106 /* ComposeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5282B922764AC47004F5106 /* ComposeView.swift */; };
C5282B942764AC47004F5106 /* ComposeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5282B922764AC47004F5106 /* ComposeView.swift */; };
C5282B972764ADD8004F5106 /* HighlightedTextEditor in Frameworks */ = {isa = PBXBuildFile; productRef = C5282B962764ADD8004F5106 /* HighlightedTextEditor */; };
Expand Down Expand Up @@ -1231,6 +1232,7 @@
buildActionMask = 2147483647;
files = (
5BC1384721C639160040353C /* Assets.xcassets in Resources */,
C527CEAE2770526F0086397A /* Localizable.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<key>Icro-Next.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
<integer>5</integer>
</dict>
<key>Icro-Share.xcscheme_^#shared#^_</key>
<dict>
Expand Down
15 changes: 11 additions & 4 deletions IcroUIKit/ViewController/ComposeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct ComposeView: View {
@State var insertLinkActive = false
@State var insertImageURLActive = false

var didClose: (() -> Void)?

init(viewModel: ComposeViewModel) {
self.viewModel = viewModel
}
Expand Down Expand Up @@ -85,7 +87,7 @@ struct ComposeView: View {
.navigationBarItems(
leading:
Button(NSLocalizedString("COMPOSEVIEWCONTROLLER_CANCELBUTTON_TITLE", comment: "")) {
dismiss()
dismissView()
}, trailing:
HStack {
if viewModel.uploading {
Expand All @@ -99,7 +101,7 @@ struct ComposeView: View {
viewController.showError(error: error, position: .top)
}
} else {
dismiss()
dismissView()
}
})
}
Expand All @@ -120,7 +122,7 @@ struct ComposeView: View {
viewController.showError(error: error, position: .top)
}
} else {
dismiss()
dismissView()
}
})
}
Expand All @@ -144,6 +146,11 @@ struct ComposeView: View {
return view
}

func dismissView() {
didClose?()
dismiss()
}

var insertLinkView: InsertLinkView {
InsertLinkView { title, url in
insertLinkActive = false
Expand Down Expand Up @@ -171,7 +178,7 @@ private struct ReplyView: View {
var body: some View {
VStack(alignment: .leading) {
ItemView(item: item)
Text("COMPOSEVIEWCONTROLLER_TABLEVIEW_HEADER_TITLE")
Text(NSLocalizedString("COMPOSEVIEWCONTROLLER_TABLEVIEW_HEADER_TITLE", comment: ""))
.font(.headline).bold()
}
.padding()
Expand Down

0 comments on commit 69dde10

Please sign in to comment.