Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Add `PlatformInfo` module (#4877)

authored by

Hailey and committed by
GitHub
18b42339 fb278384

+92 -38
+10
jest/jestSetup.js
··· 95 95 nativeApplicationVersion: '1.0.0', 96 96 nativeBuildVersion: '1', 97 97 })) 98 + 99 + jest.mock('expo-modules-core', () => ({ 100 + requireNativeModule: jest.fn().mockImplementation(moduleName => { 101 + if (moduleName === 'ExpoPlatformInfo') { 102 + return { 103 + getIsReducedMotionEnabled: () => false, 104 + } 105 + } 106 + }), 107 + }))
+24
modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/platforminfo/ExpoPlatformInfoModule.kt
··· 1 + package expo.modules.blueskyswissarmy.platforminfo 2 + 3 + import android.provider.Settings 4 + import expo.modules.kotlin.modules.Module 5 + import expo.modules.kotlin.modules.ModuleDefinition 6 + 7 + class ExpoPlatformInfoModule : Module() { 8 + override fun definition() = 9 + ModuleDefinition { 10 + Name("ExpoPlatformInfo") 11 + 12 + // See https://github.com/software-mansion/react-native-reanimated/blob/7df5fd57d608fe25724608835461cd925ff5151d/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java#L242 13 + Function("getIsReducedMotionEnabled") { 14 + val resolver = appContext.reactContext?.contentResolver ?: return@Function false 15 + val scale = Settings.Global.getString(resolver, Settings.Global.TRANSITION_ANIMATION_SCALE) ?: return@Function false 16 + 17 + try { 18 + return@Function scale.toFloat() == 0f 19 + } catch (_: Error) { 20 + return@Function false 21 + } 22 + } 23 + } 24 + }
+3 -2
modules/expo-bluesky-swiss-army/expo-module.config.json
··· 1 1 { 2 2 "platforms": ["ios", "tvos", "android", "web"], 3 3 "ios": { 4 - "modules": ["ExpoBlueskySharedPrefsModule", "ExpoBlueskyReferrerModule"] 4 + "modules": ["ExpoBlueskySharedPrefsModule", "ExpoBlueskyReferrerModule", "ExpoPlatformInfoModule"] 5 5 }, 6 6 "android": { 7 7 "modules": [ 8 8 "expo.modules.blueskyswissarmy.sharedprefs.ExpoBlueskySharedPrefsModule", 9 - "expo.modules.blueskyswissarmy.referrer.ExpoBlueskyReferrerModule" 9 + "expo.modules.blueskyswissarmy.referrer.ExpoBlueskyReferrerModule", 10 + "expo.modules.blueskyswissarmy.platforminfo.ExpoPlatformInfoModule" 10 11 ] 11 12 } 12 13 }
+2 -1
modules/expo-bluesky-swiss-army/index.ts
··· 1 + import * as PlatformInfo from './src/PlatformInfo' 1 2 import * as Referrer from './src/Referrer' 2 3 import * as SharedPrefs from './src/SharedPrefs' 3 4 4 - export {Referrer, SharedPrefs} 5 + export {PlatformInfo, Referrer, SharedPrefs}
+11
modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
··· 1 + import ExpoModulesCore 2 + 3 + public class ExpoPlatformInfoModule: Module { 4 + public func definition() -> ModuleDefinition { 5 + Name("ExpoPlatformInfo") 6 + 7 + Function("getIsReducedMotionEnabled") { 8 + return UIAccessibility.isReduceMotionEnabled 9 + } 10 + } 11 + }
+7
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts
··· 1 + import {requireNativeModule} from 'expo-modules-core' 2 + 3 + const NativeModule = requireNativeModule('ExpoPlatformInfo') 4 + 5 + export function getIsReducedMotionEnabled(): boolean { 6 + return NativeModule.getIsReducedMotionEnabled() 7 + }
+5
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts
··· 1 + import {NotImplementedError} from '../NotImplemented' 2 + 3 + export function getIsReducedMotionEnabled(): boolean { 4 + throw new NotImplementedError() 5 + }
+6
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts
··· 1 + export function getIsReducedMotionEnabled(): boolean { 2 + if (typeof window === 'undefined') { 3 + return false 4 + } 5 + return window.matchMedia('(prefers-reduced-motion: reduce)').matches 6 + }
-28
patches/react-native-reanimated+3.11.0.patch
··· 207 207 208 208 const { layout, entering, exiting, sharedTransitionTag } = this.props; 209 209 if ( 210 - diff --git a/node_modules/react-native-reanimated/lib/module/reanimated2/index.js b/node_modules/react-native-reanimated/lib/module/reanimated2/index.js 211 - index ac9be5d..86d4605 100644 212 - --- a/node_modules/react-native-reanimated/lib/module/reanimated2/index.js 213 - +++ b/node_modules/react-native-reanimated/lib/module/reanimated2/index.js 214 - @@ -47,4 +47,5 @@ export { LayoutAnimationConfig } from './component/LayoutAnimationConfig'; 215 - export { PerformanceMonitor } from './component/PerformanceMonitor'; 216 - export { startMapper, stopMapper } from './mappers'; 217 - export { startScreenTransition, finishScreenTransition, ScreenTransition } from './screenTransition'; 218 - +export { isReducedMotion } from './PlatformChecker'; 219 - //# sourceMappingURL=index.js.map 220 - diff --git a/node_modules/react-native-reanimated/lib/typescript/reanimated2/index.d.ts b/node_modules/react-native-reanimated/lib/typescript/reanimated2/index.d.ts 221 - index f01dc57..161ef22 100644 222 - --- a/node_modules/react-native-reanimated/lib/typescript/reanimated2/index.d.ts 223 - +++ b/node_modules/react-native-reanimated/lib/typescript/reanimated2/index.d.ts 224 - @@ -36,3 +36,4 @@ export type { FlatListPropsWithLayout } from './component/FlatList'; 225 - export { startMapper, stopMapper } from './mappers'; 226 - export { startScreenTransition, finishScreenTransition, ScreenTransition, } from './screenTransition'; 227 - export type { AnimatedScreenTransition, GoBackGesture, ScreenTransitionConfig, } from './screenTransition'; 228 - +export { isReducedMotion } from './PlatformChecker'; 229 - diff --git a/node_modules/react-native-reanimated/src/reanimated2/index.ts b/node_modules/react-native-reanimated/src/reanimated2/index.ts 230 - index 5885fa1..a3c693f 100644 231 - --- a/node_modules/react-native-reanimated/src/reanimated2/index.ts 232 - +++ b/node_modules/react-native-reanimated/src/reanimated2/index.ts 233 - @@ -284,3 +284,4 @@ export type { 234 - GoBackGesture, 235 - ScreenTransitionConfig, 236 - } from './screenTransition'; 237 - +export { isReducedMotion } from './PlatformChecker';
-3
src/platform/detection.ts
··· 1 1 import {Platform} from 'react-native' 2 - import {isReducedMotion} from 'react-native-reanimated' 3 2 import {getLocales} from 'expo-localization' 4 3 5 4 import {fixLegacyLanguageCode} from '#/locale/helpers' ··· 21 20 .map?.(locale => fixLegacyLanguageCode(locale.languageCode)) 22 21 .filter(code => typeof code === 'string'), 23 22 ) as string[] 24 - 25 - export const prefersReducedMotion = isReducedMotion()
+2 -2
src/state/a11y.tsx
··· 1 1 import React from 'react' 2 2 import {AccessibilityInfo} from 'react-native' 3 - import {isReducedMotion} from 'react-native-reanimated' 4 3 5 4 import {isWeb} from '#/platform/detection' 5 + import {PlatformInfo} from '../../modules/expo-bluesky-swiss-army' 6 6 7 7 const Context = React.createContext({ 8 8 reduceMotionEnabled: false, ··· 15 15 16 16 export function Provider({children}: React.PropsWithChildren<{}>) { 17 17 const [reduceMotionEnabled, setReduceMotionEnabled] = React.useState(() => 18 - isReducedMotion(), 18 + PlatformInfo.getIsReducedMotionEnabled(), 19 19 ) 20 20 const [screenReaderEnabled, setScreenReaderEnabled] = React.useState(false) 21 21
+3 -2
src/state/persisted/schema.ts
··· 1 1 import {z} from 'zod' 2 2 3 - import {deviceLocales, prefersReducedMotion} from '#/platform/detection' 3 + import {deviceLocales} from '#/platform/detection' 4 + import {PlatformInfo} from '../../../modules/expo-bluesky-swiss-army' 4 5 5 6 const externalEmbedOptions = ['show', 'hide'] as const 6 7 ··· 128 129 lastSelectedHomeFeed: undefined, 129 130 pdsAddressHistory: [], 130 131 disableHaptics: false, 131 - disableAutoplay: prefersReducedMotion, 132 + disableAutoplay: PlatformInfo.getIsReducedMotionEnabled(), 132 133 kawaii: false, 133 134 hasCheckedForStarterPack: false, 134 135 }
+19
src/view/screens/Storybook/Dialogs.tsx
··· 9 9 import * as Dialog from '#/components/Dialog' 10 10 import * as Prompt from '#/components/Prompt' 11 11 import {H3, P, Text} from '#/components/Typography' 12 + import {PlatformInfo} from '../../../../modules/expo-bluesky-swiss-army' 12 13 13 14 export function Dialogs() { 14 15 const scrollable = Dialog.useDialogControl() ··· 17 18 const testDialog = Dialog.useDialogControl() 18 19 const {closeAllDialogs} = useDialogStateControlContext() 19 20 const unmountTestDialog = Dialog.useDialogControl() 21 + const [reducedMotionEnabled, setReducedMotionEnabled] = 22 + React.useState<boolean>() 20 23 const [shouldRenderUnmountTest, setShouldRenderUnmountTest] = 21 24 React.useState(false) 22 25 const unmountTestInterval = React.useRef<number>() ··· 145 148 label="two" 146 149 testID="sharedPrefsTestOpenBtn"> 147 150 <ButtonText>Open Shared Prefs Tester</ButtonText> 151 + </Button> 152 + 153 + <Button 154 + variant="solid" 155 + color="primary" 156 + size="small" 157 + onPress={() => { 158 + const isReducedMotionEnabled = 159 + PlatformInfo.getIsReducedMotionEnabled() 160 + setReducedMotionEnabled(isReducedMotionEnabled) 161 + }} 162 + label="two"> 163 + <ButtonText> 164 + Is reduced motion enabled?: ( 165 + {reducedMotionEnabled?.toString() || 'undefined'}) 166 + </ButtonText> 148 167 </Button> 149 168 150 169 <Prompt.Outer control={prompt}>