Skip to content

Commit

Permalink
feat: Remove ui.darkmode.enabled flag condition
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Sep 24, 2024
1 parent f9c42b6 commit 32564a5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 66 deletions.
20 changes: 2 additions & 18 deletions src/app/theme/colorScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { useEffect } from 'react'
import { Appearance, ColorSchemeName } from 'react-native'

import { useSettings } from 'cozy-client'
import flag from 'cozy-flags'

interface GetColorSchemeOptions {
useUserColorScheme?: boolean
}

export const setColorScheme = (
colorScheme: ColorSchemeName | string | undefined
Expand All @@ -15,19 +10,8 @@ export const setColorScheme = (
Appearance.setColorScheme(formattedColorScheme)
}

export const getColorScheme = ({
useUserColorScheme = false
}: GetColorSchemeOptions = {}): ColorSchemeName => {
if (!useUserColorScheme) {
return Appearance.getColorScheme()
}

if (flag('ui.darkmode.enabled')) {
return Appearance.getColorScheme()
}

// Force light if flag disabled
return 'light'
export const getColorScheme = (): ColorSchemeName => {
return Appearance.getColorScheme()
}

const formatColorSchemeName = (
Expand Down
20 changes: 4 additions & 16 deletions src/app/theme/themeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,17 @@ export function setHomeTheme(params: HomeThemeParams): void {
flagshipUIEvents.SET_COMPONENT_COLORS,
componentId,
{
topTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'dark'
: 'light',
bottomTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'dark'
: 'light'
topTheme: getColorScheme() === 'dark' ? 'dark' : 'light',
bottomTheme: getColorScheme() === 'dark' ? 'dark' : 'light'
}
)
} else {
flagshipUIEventHandler.emit(
flagshipUIEvents.SET_COMPONENT_COLORS,
componentId,
{
topTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark',
bottomTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark'
topTheme: getColorScheme() === 'dark' ? 'light' : 'dark',
bottomTheme: getColorScheme() === 'dark' ? 'light' : 'dark'
}
)
}
Expand Down
12 changes: 3 additions & 9 deletions src/screens/cozy-app/CozyAppScreen.Animation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Animation = ({
).current
const animateFadeOut = useRef(new Animated.Value(1)).current
const animateBarOpacity = useRef(new Animated.Value(0)).current
const colors = getColors({ useUserColorScheme: true })
const colors = getColors()

const { setFlagshipColors } = useFlagshipUI(
'CozyAppScreenAnimation',
Expand Down Expand Up @@ -70,14 +70,8 @@ export const Animation = ({
]).start(() => {
onFirstHalf(true)
setFlagshipColors({
topTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark',
bottomTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark'
topTheme: getColorScheme() === 'dark' ? 'light' : 'dark',
bottomTheme: getColorScheme() === 'dark' ? 'light' : 'dark'
})

Animated.timing(animateBarOpacity, progressBarAnimConfig.fadeIn).start()
Expand Down
2 changes: 1 addition & 1 deletion src/screens/cozy-app/CozyAppScreen.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const config = {
// Width has to be null at start even if it's not a valid value (was set to undefined and it broke the progress bar)
// At the time of this fix we want to go back the previously working value but we have to investigate why it has to be null
export const progressBarConfig = (): ProgressBarProps => {
const colors = getColors({ useUserColorScheme: true })
const colors = getColors()

return {
width: null as unknown as number | undefined,
Expand Down
14 changes: 4 additions & 10 deletions src/screens/cozy-app/CozyAppScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ import { CozyAppScreenProps } from './CozyAppScreen.types'
import { getColors } from '/ui/colors'

const getDefaultFlagshipUI = (): FlagshipUI => {
const colors = getColors({ useUserColorScheme: true })
const colors = getColors()

return {
bottomBackground: colors.paperBackgroundColor,
bottomTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark',
bottomTheme: getColorScheme() === 'dark' ? 'light' : 'dark',
bottomOverlay: 'transparent',
topBackground: colors.paperBackgroundColor,
topTheme:
getColorScheme({ useUserColorScheme: true }) === 'dark'
? 'light'
: 'dark',
topTheme: getColorScheme() === 'dark' ? 'light' : 'dark',
topOverlay: 'transparent'
}
}
Expand All @@ -51,7 +45,7 @@ export const CozyAppScreen = ({
const [isFirstHalf, setFirstHalf] = useState(false)
const [shouldExitAnimation, setShouldExitAnimation] = useState(false)
const { setShouldWaitCozyApp } = useHomeStateContext()
const colors = getColors({ useUserColorScheme: true })
const colors = getColors()

const { componentId } = useFlagshipUI(
'CozyAppScreen',
Expand Down
6 changes: 2 additions & 4 deletions src/ui/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ export type CozyThemeColors = typeof lightNormalColors

export interface GetColorsOptions {
variant?: CozyThemeVariant
useUserColorScheme?: boolean
}

export const getColors = ({
variant = 'normal',
useUserColorScheme = false
variant = 'normal'
}: GetColorsOptions = {}): CozyThemeColors => {
const colorScheme = getColorScheme({ useUserColorScheme })
const colorScheme = getColorScheme()

if (colorScheme === 'light') {
return variant === 'normal' ? lightNormalColors : lightInvertedColors
Expand Down
6 changes: 2 additions & 4 deletions white_label/brands/cozy/js/ui/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ export type CozyThemeColors = typeof lightNormalColors

export interface GetColorsOptions {
variant?: CozyThemeVariant
useUserColorScheme?: boolean
}

export const getColors = ({
variant = 'normal',
useUserColorScheme = false
variant = 'normal'
}: GetColorsOptions = {}): CozyThemeColors => {
const colorScheme = getColorScheme({ useUserColorScheme })
const colorScheme = getColorScheme()

if (colorScheme === 'light') {
return variant === 'normal' ? lightNormalColors : lightInvertedColors
Expand Down
6 changes: 2 additions & 4 deletions white_label/brands/mabulle/js/ui/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ export type CozyThemeColors = typeof lightNormalColors

export interface GetColorsOptions {
variant?: CozyThemeVariant
useUserColorScheme?: boolean
}

export const getColors = ({
variant = 'normal',
useUserColorScheme = false
variant = 'normal'
}: GetColorsOptions = {}): CozyThemeColors => {
const colorScheme = getColorScheme({ useUserColorScheme })
const colorScheme = getColorScheme()

if (colorScheme === 'light') {
return variant === 'normal' ? lightNormalColors : lightInvertedColors
Expand Down

0 comments on commit 32564a5

Please sign in to comment.