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

babel-plugin-react-native-style-rewrite

v1.0.0

Published

rewrite react-native style plain Object to StyleSheet object

Downloads

3

Readme

这个插件出现的原因:

  • 使用StyleSheet可以提高性能: 因为StyleSheet.create()创建的样式可以通过ID重复引用,而内联样式则每次都需要创建一个新的对象。 因为StyleSheet允许仅通过bridge发送一次样式。 所有后续使用都将引用一个ID(尚未实现)。
  • 直接写一个js对象作为样式更方便直观一点
  • 经过babel处理后自动将js对象形式的样式转换为StyleSheet.create()后的样式

使用方法

  1. 安装 yarn add babel-plugin-react-native-style-rewritenpm install babel-plugin-react-native-style-rewrite
  2. 使用 找到babel的config文件,加入此插件配置
       module.exports = {
         presets: ['module:metro-react-native-babel-preset'],
         plugins: [['import', {libraryName: '@ant-design/react-native'}]],
         env: {
           production: {
             plugins: ['react-native-paper/babel'],
           },
           development: {
             plugins: ['babel-plugin-react-native-style-rewrite'],
           },
         },
       };
    

这个插件的效果

转换前:

  const AppAll = () => {
  const [dialogShow, setDialogShow] = useState(false);
  const [loading, setLoading] = useState(true);
  return (
    <Provider store={store}>
      {loading ? (
        <>
          <Image
            style={{
              width: DEVICE_WIDTH,
              height: DEVICE_REAL_HEIGHT,
            }}
            resizeMode="stretch"
            source={require('./launch_screen.png')}
          />
          <PrivacyDialog
            dialogShow={dialogShow}
            onAgreePress={() => {
              setDialogShow(false);
              setLoading(false);
            }}
          />
        </>
      ) : (
        <App />
      )}
    </Provider>
  );
};

AppRegistry.registerComponent(appName, () => AppAll);

转换后:

  const AppAll = () => {
  // 隐私政策弹窗是否显示
  const [dialogShow, setDialogShow] = useState(false); // 第一次打开app的加载状态

  const [loading, setLoading] = useState(true);
  return <Provider store={store}>
      {loading ? <>
          <Image style={styless514055.s367479} resizeMode="stretch" source={require('./launch_screen.png')} />
          <PrivacyDialog dialogShow={dialogShow} onAgreePress={() => {
        setDialogShow(false);
        setLoading(false);
      }} />
        </> : <App />}
    </Provider>;
};

AppRegistry.registerComponent(appName, () => AppAll);
var styless514055 = StyleSheet.create({
  s367479: {
    width: DEVICE_WIDTH,
    height: DEVICE_REAL_HEIGHT
  }
});