rip out native translate (#4482)
This commit is contained in:
parent
fac5f6cdac
commit
3573f7ea40
13 changed files with 4 additions and 227 deletions
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"platforms": ["ios"],
|
||||
"ios": {
|
||||
"modules": ["ExpoBlueskyTranslateModule"]
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
export {
|
||||
isAvailable,
|
||||
isLanguageSupported,
|
||||
NativeTranslationModule,
|
||||
NativeTranslationView,
|
||||
} from './src/ExpoBlueskyTranslateView'
|
|
@ -1,20 +0,0 @@
|
|||
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),
|
||||
])
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = 'ExpoBlueskyTranslate'
|
||||
s.version = '1.0.0'
|
||||
s.summary = 'Uses SwiftUI translation to translate text.'
|
||||
s.description = 'Uses SwiftUI translation to translate text.'
|
||||
s.author = ''
|
||||
s.homepage = 'https://docs.expo.dev/modules/'
|
||||
s.platforms = { :ios => '13.4' }
|
||||
s.source = { git: '' }
|
||||
s.static_framework = true
|
||||
|
||||
s.dependency 'ExpoModulesCore'
|
||||
|
||||
# Swift/Objective-C compatibility
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
||||
}
|
||||
|
||||
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
import ExpoModulesCore
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
public class ExpoBlueskyTranslateModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoBlueskyTranslate")
|
||||
|
||||
AsyncFunction("presentAsync") { (text: String) in
|
||||
DispatchQueue.main.async { [weak state = TranslateViewState.shared] in
|
||||
state?.isPresented = true
|
||||
state?.text = text
|
||||
}
|
||||
}
|
||||
|
||||
View(ExpoBlueskyTranslateView.self) {}
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
import ExpoModulesCore
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
class TranslateViewState: ObservableObject {
|
||||
static var shared = TranslateViewState()
|
||||
|
||||
@Published var isPresented = false
|
||||
@Published var text = ""
|
||||
}
|
||||
|
||||
class ExpoBlueskyTranslateView: ExpoView {
|
||||
required init(appContext: AppContext? = nil) {
|
||||
if #available(iOS 14.0, *) {
|
||||
let hostingController = UIHostingController(rootView: TranslateView())
|
||||
super.init(appContext: appContext)
|
||||
setupHostingController(hostingController)
|
||||
} else {
|
||||
super.init(appContext: appContext)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
import SwiftUI
|
||||
// conditionally import the Translation module
|
||||
#if canImport(Translation)
|
||||
import Translation
|
||||
#endif
|
||||
|
||||
struct TranslateView: View {
|
||||
@ObservedObject var state = TranslateViewState.shared
|
||||
|
||||
var body: some View {
|
||||
if #available(iOS 17.4, *) {
|
||||
VStack {
|
||||
UIViewRepresentableWrapper(view: UIView(frame: .zero))
|
||||
}
|
||||
.translationPresentation(
|
||||
isPresented: $state.isPresented,
|
||||
text: state.text
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct UIViewRepresentableWrapper: UIViewRepresentable {
|
||||
let view: UIView
|
||||
|
||||
func makeUIView(context: Context) -> UIView {
|
||||
return view
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIView, context: Context) {}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
export type ExpoBlueskyTranslateModule = {
|
||||
presentAsync: (text: string) => Promise<void>
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
import React from 'react'
|
||||
import {Platform} from 'react-native'
|
||||
import {requireNativeModule, requireNativeViewManager} from 'expo-modules-core'
|
||||
|
||||
import {ExpoBlueskyTranslateModule} from './ExpoBlueskyTranslate.types'
|
||||
|
||||
export const NativeTranslationModule =
|
||||
requireNativeModule<ExpoBlueskyTranslateModule>('ExpoBlueskyTranslate')
|
||||
|
||||
const NativeView: React.ComponentType = requireNativeViewManager(
|
||||
'ExpoBlueskyTranslate',
|
||||
)
|
||||
|
||||
export function NativeTranslationView() {
|
||||
return <NativeView />
|
||||
}
|
||||
|
||||
// can be something like "17.5.1", so just take the first two parts
|
||||
const version = String(Platform.Version).split('.').slice(0, 2).join('.')
|
||||
|
||||
export const isAvailable = Number(version) >= 17.4
|
||||
|
||||
// https://en.wikipedia.org/wiki/Translate_(Apple)#Languages
|
||||
const SUPPORTED_LANGUAGES = [
|
||||
'ar',
|
||||
'zh',
|
||||
'zh',
|
||||
'nl',
|
||||
'en',
|
||||
'en',
|
||||
'fr',
|
||||
'de',
|
||||
'id',
|
||||
'it',
|
||||
'ja',
|
||||
'ko',
|
||||
'pl',
|
||||
'pt',
|
||||
'ru',
|
||||
'es',
|
||||
'th',
|
||||
'tr',
|
||||
'uk',
|
||||
'vi',
|
||||
]
|
||||
|
||||
export function isLanguageSupported(lang?: string) {
|
||||
// If the language is not provided, we assume it is supported
|
||||
if (!lang) return true
|
||||
return SUPPORTED_LANGUAGES.includes(lang)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
export const NativeTranslationModule = {
|
||||
presentAsync: async (_: string) => {},
|
||||
}
|
||||
|
||||
export function NativeTranslationView() {
|
||||
return null
|
||||
}
|
||||
|
||||
export const isAvailable = false
|
||||
|
||||
export function isLanguageSupported(_lang?: string) {
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue