about summary refs log tree commit diff
path: root/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-05-29 07:08:46 +0300
committerGitHub <noreply@github.com>2024-05-28 21:08:46 -0700
commitb59c8e22af0d92988d2145ea28299230f3b71180 (patch)
tree3bfc697a5e709a29ee4f71fc538e9104855f9d07 /modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
parenta60f9933d8c5734391b9f5b14c1bdb0d17ac0468 (diff)
downloadvoidsky-b59c8e22af0d92988d2145ea28299230f3b71180.tar.zst
Native translation expo module (#4098)
* translation expo module

* add `onClose` and `onReplacementAction`

* rm onReplacementAction

* make all props published

* make translation api available globally w/o wrapper (#4110)

* conditionally import the translation module

* only use native translation if language is probably supported

* open native translation via dropdown menu

---------

Co-authored-by: Hailey <me@haileyok.com>
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift')
-rw-r--r--modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift b/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
new file mode 100644
index 000000000..c8ca3e027
--- /dev/null
+++ b/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
@@ -0,0 +1,20 @@
+import ExpoModulesCore
+import SwiftUI
+
+// Thanks to Andrew Levy for this code snippet
+// https://github.com/andrew-levy/swiftui-react-native/blob/d3fbb2abf07601ff0d4b83055e7717bb980910d6/ios/Common/ExpoView%2BUIHostingController.swift
+
+extension ExpoView {
+  func setupHostingController(_ hostingController: UIHostingController<some View>) {
+    hostingController.view.translatesAutoresizingMaskIntoConstraints = false
+    hostingController.view.backgroundColor = .clear
+
+    addSubview(hostingController.view)
+    NSLayoutConstraint.activate([
+      hostingController.view.topAnchor.constraint(equalTo: self.topAnchor),
+      hostingController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor),
+      hostingController.view.leftAnchor.constraint(equalTo: self.leftAnchor),
+      hostingController.view.rightAnchor.constraint(equalTo: self.rightAnchor),
+    ])
+  }
+}