Bluesky app fork with some witchin' additions 💫

rip out native translate (#4482)

authored by samuel.fm and committed by

GitHub 3573f7ea fac5f6cd

+4 -227
-6
modules/expo-bluesky-translate/expo-module.config.json
··· 1 - { 2 - "platforms": ["ios"], 3 - "ios": { 4 - "modules": ["ExpoBlueskyTranslateModule"] 5 - } 6 - }
-6
modules/expo-bluesky-translate/index.ts
··· 1 - export { 2 - isAvailable, 3 - isLanguageSupported, 4 - NativeTranslationModule, 5 - NativeTranslationView, 6 - } from './src/ExpoBlueskyTranslateView'
-20
modules/expo-bluesky-translate/ios/Common/UIHostingControllerCompat.swift
··· 1 - import ExpoModulesCore 2 - import SwiftUI 3 - 4 - // Thanks to Andrew Levy for this code snippet 5 - // https://github.com/andrew-levy/swiftui-react-native/blob/d3fbb2abf07601ff0d4b83055e7717bb980910d6/ios/Common/ExpoView%2BUIHostingController.swift 6 - 7 - extension ExpoView { 8 - func setupHostingController(_ hostingController: UIHostingController<some View>) { 9 - hostingController.view.translatesAutoresizingMaskIntoConstraints = false 10 - hostingController.view.backgroundColor = .clear 11 - 12 - addSubview(hostingController.view) 13 - NSLayoutConstraint.activate([ 14 - hostingController.view.topAnchor.constraint(equalTo: self.topAnchor), 15 - hostingController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor), 16 - hostingController.view.leftAnchor.constraint(equalTo: self.leftAnchor), 17 - hostingController.view.rightAnchor.constraint(equalTo: self.rightAnchor), 18 - ]) 19 - } 20 - }
-21
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslate.podspec
··· 1 - Pod::Spec.new do |s| 2 - s.name = 'ExpoBlueskyTranslate' 3 - s.version = '1.0.0' 4 - s.summary = 'Uses SwiftUI translation to translate text.' 5 - s.description = 'Uses SwiftUI translation to translate text.' 6 - s.author = '' 7 - s.homepage = 'https://docs.expo.dev/modules/' 8 - s.platforms = { :ios => '13.4' } 9 - s.source = { git: '' } 10 - s.static_framework = true 11 - 12 - s.dependency 'ExpoModulesCore' 13 - 14 - # Swift/Objective-C compatibility 15 - s.pod_target_xcconfig = { 16 - 'DEFINES_MODULE' => 'YES', 17 - 'SWIFT_COMPILATION_MODE' => 'wholemodule' 18 - } 19 - 20 - s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}" 21 - end
-18
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateModule.swift
··· 1 - import ExpoModulesCore 2 - import Foundation 3 - import SwiftUI 4 - 5 - public class ExpoBlueskyTranslateModule: Module { 6 - public func definition() -> ModuleDefinition { 7 - Name("ExpoBlueskyTranslate") 8 - 9 - AsyncFunction("presentAsync") { (text: String) in 10 - DispatchQueue.main.async { [weak state = TranslateViewState.shared] in 11 - state?.isPresented = true 12 - state?.text = text 13 - } 14 - } 15 - 16 - View(ExpoBlueskyTranslateView.self) {} 17 - } 18 - }
-22
modules/expo-bluesky-translate/ios/ExpoBlueskyTranslateView.swift
··· 1 - import ExpoModulesCore 2 - import Foundation 3 - import SwiftUI 4 - 5 - class TranslateViewState: ObservableObject { 6 - static var shared = TranslateViewState() 7 - 8 - @Published var isPresented = false 9 - @Published var text = "" 10 - } 11 - 12 - class ExpoBlueskyTranslateView: ExpoView { 13 - required init(appContext: AppContext? = nil) { 14 - if #available(iOS 14.0, *) { 15 - let hostingController = UIHostingController(rootView: TranslateView()) 16 - super.init(appContext: appContext) 17 - setupHostingController(hostingController) 18 - } else { 19 - super.init(appContext: appContext) 20 - } 21 - } 22 - }
-31
modules/expo-bluesky-translate/ios/TranslateView.swift
··· 1 - import SwiftUI 2 - // conditionally import the Translation module 3 - #if canImport(Translation) 4 - import Translation 5 - #endif 6 - 7 - struct TranslateView: View { 8 - @ObservedObject var state = TranslateViewState.shared 9 - 10 - var body: some View { 11 - if #available(iOS 17.4, *) { 12 - VStack { 13 - UIViewRepresentableWrapper(view: UIView(frame: .zero)) 14 - } 15 - .translationPresentation( 16 - isPresented: $state.isPresented, 17 - text: state.text 18 - ) 19 - } 20 - } 21 - } 22 - 23 - struct UIViewRepresentableWrapper: UIViewRepresentable { 24 - let view: UIView 25 - 26 - func makeUIView(context: Context) -> UIView { 27 - return view 28 - } 29 - 30 - func updateUIView(_ uiView: UIView, context: Context) {} 31 - }
-3
modules/expo-bluesky-translate/src/ExpoBlueskyTranslate.types.ts
··· 1 - export type ExpoBlueskyTranslateModule = { 2 - presentAsync: (text: string) => Promise<void> 3 - }
-51
modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.ios.tsx
··· 1 - import React from 'react' 2 - import {Platform} from 'react-native' 3 - import {requireNativeModule, requireNativeViewManager} from 'expo-modules-core' 4 - 5 - import {ExpoBlueskyTranslateModule} from './ExpoBlueskyTranslate.types' 6 - 7 - export const NativeTranslationModule = 8 - requireNativeModule<ExpoBlueskyTranslateModule>('ExpoBlueskyTranslate') 9 - 10 - const NativeView: React.ComponentType = requireNativeViewManager( 11 - 'ExpoBlueskyTranslate', 12 - ) 13 - 14 - export function NativeTranslationView() { 15 - return <NativeView /> 16 - } 17 - 18 - // can be something like "17.5.1", so just take the first two parts 19 - const version = String(Platform.Version).split('.').slice(0, 2).join('.') 20 - 21 - export const isAvailable = Number(version) >= 17.4 22 - 23 - // https://en.wikipedia.org/wiki/Translate_(Apple)#Languages 24 - const SUPPORTED_LANGUAGES = [ 25 - 'ar', 26 - 'zh', 27 - 'zh', 28 - 'nl', 29 - 'en', 30 - 'en', 31 - 'fr', 32 - 'de', 33 - 'id', 34 - 'it', 35 - 'ja', 36 - 'ko', 37 - 'pl', 38 - 'pt', 39 - 'ru', 40 - 'es', 41 - 'th', 42 - 'tr', 43 - 'uk', 44 - 'vi', 45 - ] 46 - 47 - export function isLanguageSupported(lang?: string) { 48 - // If the language is not provided, we assume it is supported 49 - if (!lang) return true 50 - return SUPPORTED_LANGUAGES.includes(lang) 51 - }
-13
modules/expo-bluesky-translate/src/ExpoBlueskyTranslateView.tsx
··· 1 - export const NativeTranslationModule = { 2 - presentAsync: async (_: string) => {}, 3 - } 4 - 5 - export function NativeTranslationView() { 6 - return null 7 - } 8 - 9 - export const isAvailable = false 10 - 11 - export function isLanguageSupported(_lang?: string) { 12 - return false 13 - }
+2 -19
src/view/com/post-thread/PostThreadItem.tsx
··· 30 30 import {PostThreadFollowBtn} from 'view/com/post-thread/PostThreadFollowBtn' 31 31 import {atoms as a} from '#/alf' 32 32 import {RichText} from '#/components/RichText' 33 - import { 34 - isAvailable as isNativeTranslationAvailable, 35 - isLanguageSupported, 36 - NativeTranslationModule, 37 - } from '../../../../modules/expo-bluesky-translate' 38 33 import {ContentHider} from '../../../components/moderation/ContentHider' 39 34 import {LabelsOnMyPost} from '../../../components/moderation/LabelsOnMe' 40 35 import {PostAlerts} from '../../../components/moderation/PostAlerts' ··· 344 339 </ContentHider> 345 340 <ExpandedPostDetails 346 341 post={post} 347 - record={record} 348 342 translatorUrl={translatorUrl} 349 343 needsTranslation={needsTranslation} 350 344 /> ··· 653 647 654 648 function ExpandedPostDetails({ 655 649 post, 656 - record, 657 650 needsTranslation, 658 651 translatorUrl, 659 652 }: { 660 653 post: AppBskyFeedDefs.PostView 661 - record?: AppBskyFeedPost.Record 662 654 needsTranslation: boolean 663 655 translatorUrl: string 664 656 }) { ··· 666 658 const {_} = useLingui() 667 659 const openLink = useOpenLink() 668 660 669 - const text = record?.text || '' 670 - 671 661 const onTranslatePress = React.useCallback(() => { 672 - if ( 673 - isNativeTranslationAvailable && 674 - isLanguageSupported(record?.langs?.at(0)) 675 - ) { 676 - NativeTranslationModule.presentAsync(text) 677 - } else { 678 - openLink(translatorUrl) 679 - } 680 - }, [openLink, text, translatorUrl, record]) 662 + openLink(translatorUrl) 663 + }, [openLink, translatorUrl]) 681 664 682 665 return ( 683 666 <View style={[s.flexRow, s.mt2, s.mb10]}>
+2 -15
src/view/com/util/forms/PostDropdownBtn.tsx
··· 57 57 import * as Menu from '#/components/Menu' 58 58 import * as Prompt from '#/components/Prompt' 59 59 import {ReportDialog, useReportDialogControl} from '#/components/ReportDialog' 60 - import { 61 - isAvailable as isNativeTranslationAvailable, 62 - isLanguageSupported, 63 - NativeTranslationModule, 64 - } from '../../../../../modules/expo-bluesky-translate' 65 60 import {EventStopper} from '../EventStopper' 66 61 import * as Toast from '../Toast' 67 62 ··· 188 183 }, [_, richText]) 189 184 190 185 const onPressTranslate = React.useCallback(() => { 191 - if ( 192 - isNativeTranslationAvailable && 193 - isLanguageSupported(record?.langs?.at(0)) 194 - ) { 195 - const text = richTextToString(richText, true) 196 - NativeTranslationModule.presentAsync(text) 197 - } else { 198 - openLink(translatorUrl) 199 - } 200 - }, [openLink, record?.langs, richText, translatorUrl]) 186 + openLink(translatorUrl) 187 + }, [openLink, translatorUrl]) 201 188 202 189 const onHidePost = React.useCallback(() => { 203 190 hidePost({uri: postUri})
-2
src/view/shell/index.tsx
··· 33 33 import {MutedWordsDialog} from '#/components/dialogs/MutedWords' 34 34 import {SigninDialog} from '#/components/dialogs/Signin' 35 35 import {Outlet as PortalOutlet} from '#/components/Portal' 36 - import {NativeTranslationView} from '../../../modules/expo-bluesky-translate' 37 36 import {RoutesContainer, TabsNavigator} from '../../Navigation' 38 37 import {Composer} from './Composer' 39 38 import {DrawerContent} from './Drawer' ··· 94 93 </Drawer> 95 94 </ErrorBoundary> 96 95 </Animated.View> 97 - <NativeTranslationView /> 98 96 <Composer winHeight={winDim.height} /> 99 97 <ModalsContainer /> 100 98 <MutedWordsDialog />