From 3573f7ea40d41b8c416194da31fbbad092062679 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 11 Jun 2024 18:51:03 +0100 Subject: [PATCH] rip out native translate (#4482) --- .../expo-module.config.json | 6 --- modules/expo-bluesky-translate/index.ts | 6 --- .../Common/UIHostingControllerCompat.swift | 20 -------- .../ios/ExpoBlueskyTranslate.podspec | 21 -------- .../ios/ExpoBlueskyTranslateModule.swift | 18 ------- .../ios/ExpoBlueskyTranslateView.swift | 22 -------- .../ios/TranslateView.swift | 31 ----------- .../src/ExpoBlueskyTranslate.types.ts | 3 -- .../src/ExpoBlueskyTranslateView.ios.tsx | 51 ------------------- .../src/ExpoBlueskyTranslateView.tsx | 13 ----- src/view/com/post-thread/PostThreadItem.tsx | 21 +------- src/view/com/util/forms/PostDropdownBtn.tsx | 17 +------ src/view/shell/index.tsx | 2 - 13 files changed, 4 insertions(+), 227 deletions(-) delete mode 100644 modules/expo-bluesky-translate/expo-module.config.json delete mode 100644 modules/expo-bluesky-translate/index.ts delete mode 100644 modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift delete mode 100644 modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec delete mode 100644 modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift delete mode 100644 modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift delete mode 100644 modules/expo-bluesky-translate/ios/TranslateView.swift delete mode 100644 modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts delete mode 100644 modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx delete mode 100644 modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx diff --git a/modules/expo-bluesky-translate/expo-module.config.json b/modules/expo-bluesky-translate/expo-module.config.json deleted file mode 100644 index 28c5dd87..00000000 --- a/modules/expo-bluesky-translate/expo-module.config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "platforms": ["ios"], - "ios": { - "modules": ["ExpoBlueskyTranslateModule"] - } -} diff --git a/modules/expo-bluesky-translate/index.ts b/modules/expo-bluesky-translate/index.ts deleted file mode 100644 index f3e1d3b1..00000000 --- a/modules/expo-bluesky-translate/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { - isAvailable, - isLanguageSupported, - NativeTranslationModule, - NativeTranslationView, -} from './src/ExpoBlueskyTranslateView' diff --git a/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift b/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift deleted file mode 100644 index c8ca3e02..00000000 --- a/modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift +++ /dev/null @@ -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) { - 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), - ]) - } -} diff --git a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec b/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec deleted file mode 100644 index 45f86a60..00000000 --- a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec +++ /dev/null @@ -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 diff --git a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift b/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift deleted file mode 100644 index afa81372..00000000 --- a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift +++ /dev/null @@ -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) {} - } -} diff --git a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift b/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift deleted file mode 100644 index ca6e3be6..00000000 --- a/modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift +++ /dev/null @@ -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) - } - } -} diff --git a/modules/expo-bluesky-translate/ios/TranslateView.swift b/modules/expo-bluesky-translate/ios/TranslateView.swift deleted file mode 100644 index e2886dc8..00000000 --- a/modules/expo-bluesky-translate/ios/TranslateView.swift +++ /dev/null @@ -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) {} -} diff --git a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts b/modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts deleted file mode 100644 index a01d4d47..00000000 --- a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type ExpoBlueskyTranslateModule = { - presentAsync: (text: string) => Promise -} diff --git a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx b/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx deleted file mode 100644 index 290fabd3..00000000 --- a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx +++ /dev/null @@ -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('ExpoBlueskyTranslate') - -const NativeView: React.ComponentType = requireNativeViewManager( - 'ExpoBlueskyTranslate', -) - -export function NativeTranslationView() { - return -} - -// 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) -} diff --git a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx b/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx deleted file mode 100644 index 16ff9d60..00000000 --- a/modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx +++ /dev/null @@ -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 -} diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index 4827aef5..5ee60e4e 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -30,11 +30,6 @@ import {useSession} from 'state/session' import {PostThreadFollowBtn} from 'view/com/post-thread/PostThreadFollowBtn' import {atoms as a} from '#/alf' import {RichText} from '#/components/RichText' -import { - isAvailable as isNativeTranslationAvailable, - isLanguageSupported, - NativeTranslationModule, -} from '../../../../modules/expo-bluesky-translate' import {ContentHider} from '../../../components/moderation/ContentHider' import {LabelsOnMyPost} from '../../../components/moderation/LabelsOnMe' import {PostAlerts} from '../../../components/moderation/PostAlerts' @@ -344,7 +339,6 @@ let PostThreadItemLoaded = ({ @@ -653,12 +647,10 @@ function PostOuterWrapper({ function ExpandedPostDetails({ post, - record, needsTranslation, translatorUrl, }: { post: AppBskyFeedDefs.PostView - record?: AppBskyFeedPost.Record needsTranslation: boolean translatorUrl: string }) { @@ -666,18 +658,9 @@ function ExpandedPostDetails({ const {_} = useLingui() const openLink = useOpenLink() - const text = record?.text || '' - const onTranslatePress = React.useCallback(() => { - if ( - isNativeTranslationAvailable && - isLanguageSupported(record?.langs?.at(0)) - ) { - NativeTranslationModule.presentAsync(text) - } else { - openLink(translatorUrl) - } - }, [openLink, text, translatorUrl, record]) + openLink(translatorUrl) + }, [openLink, translatorUrl]) return ( diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index 945cf5e5..b6873ff8 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -57,11 +57,6 @@ import {Warning_Stroke2_Corner0_Rounded as Warning} from '#/components/icons/War import * as Menu from '#/components/Menu' import * as Prompt from '#/components/Prompt' import {ReportDialog, useReportDialogControl} from '#/components/ReportDialog' -import { - isAvailable as isNativeTranslationAvailable, - isLanguageSupported, - NativeTranslationModule, -} from '../../../../../modules/expo-bluesky-translate' import {EventStopper} from '../EventStopper' import * as Toast from '../Toast' @@ -188,16 +183,8 @@ let PostDropdownBtn = ({ }, [_, richText]) const onPressTranslate = React.useCallback(() => { - if ( - isNativeTranslationAvailable && - isLanguageSupported(record?.langs?.at(0)) - ) { - const text = richTextToString(richText, true) - NativeTranslationModule.presentAsync(text) - } else { - openLink(translatorUrl) - } - }, [openLink, record?.langs, richText, translatorUrl]) + openLink(translatorUrl) + }, [openLink, translatorUrl]) const onHidePost = React.useCallback(() => { hidePost({uri: postUri}) diff --git a/src/view/shell/index.tsx b/src/view/shell/index.tsx index 317ac0bd..7d080e57 100644 --- a/src/view/shell/index.tsx +++ b/src/view/shell/index.tsx @@ -33,7 +33,6 @@ import {ErrorBoundary} from 'view/com/util/ErrorBoundary' import {MutedWordsDialog} from '#/components/dialogs/MutedWords' import {SigninDialog} from '#/components/dialogs/Signin' import {Outlet as PortalOutlet} from '#/components/Portal' -import {NativeTranslationView} from '../../../modules/expo-bluesky-translate' import {RoutesContainer, TabsNavigator} from '../../Navigation' import {Composer} from './Composer' import {DrawerContent} from './Drawer' @@ -94,7 +93,6 @@ function ShellInner() { -