npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rn-darkly

v2.1.0

Published

对 react-native 组件进行暗黑模式封装

Downloads

49

Readme

rn-darkly

对 react-native 组件进行暗黑模式封装

  1. 支持 useColorScheme api 自动切换为暗黑模式,在不支持此 api 的版本降级为非暗黑模式,但依旧可以手动设置强制暗黑模式/非暗黑模式
  2. 支持设置暗黑模式样式
  3. 支持强制暗黑模式/非暗黑模式
  4. 支持配置全局强制暗黑模式/非暗黑模式

install

npm

npm install rn-darkly --save

yarn

yarn add rn-darkly

示例

import React, { useState } from 'react';
import {
  DarklyText,
  DarklySafeAreaView,
  DarklyScrollView,
  DarklyTouchableHighlight,
  DarklyProvider,
  DarklyStatusBar,
} from 'rn-darkly';

export default function App() {
  const [forceDark, setForceDark] = useState(false);

  return (
    // 外层包裹 DarklyProvider
    <DarklyProvider forceDark={forceDark}>
      <DarklyStatusBar barStyle="dark-content" dark_barStyle="light-content" />
      <DarklyScrollView
        contentContainerStyle={{ backgroundColor: '#fafafa', flex: 1 }}
        dark_contentContainerStyle={{ backgroundColor: '#000' }}>
        <DarklySafeAreaView>
          <DarklyTouchableHighlight
            onPress={() => setForceDark(!forceDark)}
            style={{ height: 50 }}
            dark_underlayColor="#eee"
            underlayColor="#000">
            <DarklyText
              style={{ fontSize: 20, color: '#333' }}
              dark_style={{ color: '#fff' }}>
              DarklyText
            </DarklyText>
          </DarklyTouchableHighlight>
        </DarklySafeAreaView>
      </DarklyScrollView>
    </DarklyProvider>
  );
}

darkly

高阶组件,使一个普通组件支持暗黑模式

示例

// 第一个参数就是要支持暗黑模式的组件
// 是否参数就是这个组件要支持暗黑模式的属性的key
// 如果是以style结尾(barStyle除外,StatusBar的barStyle不是样式),会被认为是样式,其余就任务是普通属性
// 样式会以数组形式往下传递
// 例如默认情况下,我们设置的 style 是 {width: 100, backgroundColor: '#fff'} dark_style 是 {backgroundColor: '#000'}
// 这时实际传入ScrollView的style会是 [{width: 100, backgroundColor: '#fff'},{backgroundColor: '#000'}]
// 如果不是以style结尾,就会被替换掉
const DarklyScrollView = darkly(ScrollView, 'style', 'contentContainerStyle');

Props

DarklyProvider

| 名称 | 默认值 | 类型 | 描述 | | ----------------------- | :----------------------: | :-----------------------------------------------------------------------------: | :----------------------------------------------------------- | | forceDark | - | boolean | 强制设置全局暗黑模式/非暗黑模式 | | children | - | React.ReactNode | 要展示的组件 |


DarklyComponent

例如 DarklyScrollView

| 名称 | 默认值 | 类型 | 描述 | | ----------------------- | :----------------------: | :-----------------------------------------------------------------------------: | :----------------------------------------------------------- | | forceDark | - | boolean | 强制设置暗黑模式/非暗黑模式 | | dark_style | - | StyleProp | 暗黑模式样式 | | dark_contentContainerStyle | - | StyleProp | 暗黑模式样式 |

例如 DarklyView