我如何使Expo Image Picker Dark主题

发布于 2025-02-10 09:38:58 字数 403 浏览 3 评论 0原文

这是我当前的图像拾取器功能,

const pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.images,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
  
    })
    
    console.log(result)

    if (!result.cancelled) {
      setImage(result.uri)
    }
  }

我正在尝试使弹出画廊以黑暗为主题。我该怎么做?

This is my current image picker function

const pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.images,
      allowsEditing: true,
      aspect: [4, 3],
      quality: 1,
  
    })
    
    console.log(result)

    if (!result.cancelled) {
      setImage(result.uri)
    }
  }

I am trying to make the pop-up gallery dark-themed. How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小巷里的女流氓 2025-02-17 09:38:59

React Navigation具有一个理想选择的主题组件!您可以使用他们的默认主题,也可以根据需要自定义!查看详细信息在这里。

在项目中添加主题实际上非常容易。假设您已经在使用React-Navigation,那么您甚至不需要下载额外的依赖项。

创建一个新的.js文件,称为您想要的任何内容,典型名称将为theme.js。粘贴内部:

import * as React from 'react';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';

const MyTheme = {
  ...DefaultTheme,
  colors: {
    ...DefaultTheme.colors,
    primary: 'rgb(255, 45, 85)',
  },
};

此主题组件有很多道具可供选择,因此请务必检查一下。

这是文档中的一个示例:

const MyTheme = {
  dark: false,
  colors: {
    primary: 'rgb(255, 45, 85)',
    background: 'rgb(242, 242, 242)',
    card: 'rgb(255, 255, 255)',
    text: 'rgb(28, 28, 30)',
    border: 'rgb(199, 199, 204)',
    notification: 'rgb(255, 69, 58)',
  },
};

现在,对于黑暗模式部分,React-Navigation已内置为主题,默认和黑暗:import {defaultTheme,darktheme,darktheme} from'@react-navigation/naters';>

在导航容器内部,现在您要做的就是调用您要使用的主题:

import { useColorScheme } from 'react-native';
import {
  NavigationContainer,
  DefaultTheme,
  DarkTheme,
} from '@react-navigation/native';

export default () => {
  const scheme = useColorScheme();

  return (
    <NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
      {/* content */}
    </NavigationContainer>
  );
};

这是从轻度和黑暗主题开始的绝佳方法。一旦掌握了它,您也可以实现状态,以使您的应用在默认模式和黑暗模式之间切换!

React Navigation has a Theme component that would be perfect for this! You can use their default theme, or customize it however you want! Check out details here.

Adding a theme to your project is actually super easy. Assuming you're already using React-Navigation, then you don't even need to download an additional dependency.

Create a new .js file called whatever you want, typical name would be theme.js. Inside paste this:

import * as React from 'react';
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';

const MyTheme = {
  ...DefaultTheme,
  colors: {
    ...DefaultTheme.colors,
    primary: 'rgb(255, 45, 85)',
  },
};

This theme component has a whole bunch of props to choose from so make sure to check it out.

Here is an example from the docs:

const MyTheme = {
  dark: false,
  colors: {
    primary: 'rgb(255, 45, 85)',
    background: 'rgb(242, 242, 242)',
    card: 'rgb(255, 255, 255)',
    text: 'rgb(28, 28, 30)',
    border: 'rgb(199, 199, 204)',
    notification: 'rgb(255, 69, 58)',
  },
};

Now for the dark mode portion, React-Navigation has built in themes, default and dark: import { DefaultTheme, DarkTheme } from '@react-navigation/native';

Inside your navigation container, now all you have to do is call the theme you'd like to use:

import { useColorScheme } from 'react-native';
import {
  NavigationContainer,
  DefaultTheme,
  DarkTheme,
} from '@react-navigation/native';

export default () => {
  const scheme = useColorScheme();

  return (
    <NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
      {/* content */}
    </NavigationContainer>
  );
};

This is a great rudimentary way to get start with light and dark themes. Once you get the hang of it, you can implement State as well to make your app toggle between default and dark mode!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文