首页 > 解决方案 > 尝试修复 React Native 中的暗模式,适用于 Android

问题描述

我必须在主要针对 IOS 的 ReactNative 应用程序上修复暗模式。我想我现在可以在大多数文件中解决一半的问题,但是有一个名为 Colors.js 的文件,带有 DynamicColorsIOS。我尝试使用“外观”,几乎所有东西都变暗了,但它不是动态的。然后我发现了关于 PlatformColor,但我不确定如何使用它。

这是一段代码,如果有人可以帮助我理解。

 /* New palette */
  pinkPrimary: {
    light: primitiveColors.pinkPrimary,
    dark: primitiveColors.pinkPrimary,
  },
  backPrimary: {
    light: primitiveColors.blackPrimary,
    dark: primitiveColors.blackPrimary,
  },
  grayPrimary: {
    light: primitiveColors.grayPrimary,
    dark: primitiveColors.grayPrimary,
  },
  grayButtonIcon: {
    light: primitiveColors.grayButtonIcon,
    dark: primitiveColors.grayButtonIcon,
  },
  gray3: {
    light: primitiveColors.gray3,
    dark: primitiveColors.gray3,
  },
  gray4: {
    light: primitiveColors.gray4,
    dark: primitiveColors.gray4,
  },
}

const colorsForPlatform = Object.keys(colors).reduce((memo, name) => {

  if (Platform.OS === 'ios') {
    memo[name] = DynamicColorIOS(colors[name])
  } else {
    memo[name] = colors[name].light
    // Don't know how PlatformColor works, or if it's what I should use here..
    // memo[name] = PlatformColor(colors[name])
    //
  }
console.log(colors[name])
  return memo
}, {})

标签: javascriptreact-nativeandroid-dark-theme

解决方案


推荐阅读