this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Disable animations for translation events on Android (#10013)

authored by

DS Boyce and committed by
GitHub
290e0f2b ece6dc25

+20 -15
+20 -15
src/lib/translation/index.tsx
··· 9 9 import {useGoogleTranslate} from '#/lib/hooks/useGoogleTranslate' 10 10 import {logger} from '#/logger' 11 11 import {useAnalytics} from '#/analytics' 12 - import {HAS_ON_DEVICE_TRANSLATION} from '#/env' 12 + import {HAS_ON_DEVICE_TRANSLATION, IS_ANDROID, IS_IOS} from '#/env' 13 13 import {Context} from './context' 14 14 import {type TranslationFunctionParams, type TranslationState} from './types' 15 15 import {guessLanguage} from './utils' ··· 34 34 // Note that Android only supports two-character language codes and will fail 35 35 // on other input. 36 36 // https://developers.google.com/android/reference/com/google/mlkit/nl/translate/TranslateLanguage 37 - let targetLangCode = 38 - Platform.OS === 'android' 39 - ? targetLangCodeOriginal.split('-')[0] 40 - : targetLangCodeOriginal 41 - const sourceLangCode = 42 - Platform.OS === 'android' 43 - ? sourceLangCodeOriginal?.split('-')[0] 44 - : sourceLangCodeOriginal 37 + let targetLangCode = IS_ANDROID 38 + ? targetLangCodeOriginal.split('-')[0] 39 + : targetLangCodeOriginal 40 + const sourceLangCode = IS_ANDROID 41 + ? sourceLangCodeOriginal?.split('-')[0] 42 + : sourceLangCodeOriginal 45 43 46 44 // Special cases for regional languages since iOS differentiates and missing 47 45 // language packs must be downloaded and installed. 48 - if (Platform.OS === 'ios') { 46 + if (IS_IOS) { 49 47 const deviceLocales = getLocales() 50 48 const primaryLanguageTag = deviceLocales[0]?.languageTag 51 49 switch (targetLangCodeOriginal) { ··· 192 190 }, []) 193 191 194 192 const clearTranslation = useCallback((key: string) => { 195 - LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 193 + if (!IS_ANDROID) { 194 + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 195 + } 196 196 setTranslationState(prev => { 197 197 delete prev[key] 198 198 return {...prev} ··· 224 224 return 225 225 } 226 226 227 - // Translate after the next state change. 228 - LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 227 + if (!IS_ANDROID) { 228 + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 229 + } 229 230 setTranslationState(prev => ({ 230 231 ...prev, 231 232 [key]: {status: 'loading'}, ··· 242 243 sourceLanguage: result.sourceLanguage, 243 244 targetLanguage: result.targetLanguage, 244 245 }) 245 - LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 246 + if (!IS_ANDROID) { 247 + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 248 + } 246 249 setTranslationState(prev => ({ 247 250 ...prev, 248 251 [key]: { ··· 263 266 targetLanguage: targetLangCode, 264 267 }) 265 268 let errorMessage = l`Device failed to translate :(` 266 - LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 269 + if (!IS_ANDROID) { 270 + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 271 + } 267 272 setTranslationState(prev => ({ 268 273 ...prev, 269 274 [key]: {status: 'error', message: errorMessage},