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

react-native-stylex

v4.2.1

Published

Better styling for react-native

Downloads

1,887

Readme

react-native-stylex

Better styling for react-native

react-native-stylex on npm react-native-stylex downloads react-native-stylex bundle size CI status

Module features:

Integrations

Links

Install

react-native-stylex requires react-native 0.59.0 or later.

1️⃣ Add module

yarn add react-native-stylex

# or npm install react-native-stylex

2️⃣ Add theme <ThemeProvider/>

Stylex provides component, which makes the theme available to the rest of your app:

import { ThemeProvider } from "react-native-stylex";
import {
  createBreakpointsMatcher,
  createBreakpoints,
  maxWidth,
} from "react-native-stylex/media-query";

const breakpoints = {
  xs: 360,
  sm: 600,
  md: 960,
  lg: 1280,
  xl: 1920,
};
const { up, down, only, between } = createBreakpoints(breakpoints);
const applyBreakpoints = createBreakpointsMatcher(breakpoints, maxWidth);

const theme = {
  palette: { textColor: "black" },
  breakpoints: { up, down, only, between, apply: applyBreakpoints },
  utils: {
    fade: (color, value) => {},
  },
};

const Root = () => (
  <ThemeProvider value={theme}>
    <App />
  </ThemeProvider>
);

export default Root;

3️⃣ Create styles makeUseStyles(...)

Stylex provides a helper function to inject styles to your component.

Normally, you’ll use it in this way:

import { makeUseStyles } from "react-native-stylex";
import { maxWidth } from "react-native-stylex/media-query";

export const useStyles = makeUseStyles(({ palette, utils, breakpoints }) => ({
  root: {
    color: utils.fade(palette.textColor, 0.5),
    height: 100,
    // On screens that are 320 or less, set the height to 69
    ...maxWidth(320, { height: 69 }),
  },

  text: {
    fontSize: 16, // default value
    ...breakpoints.down("lg", { fontSize: 18 }), // if window width 0..1280
    ...breakpoints.down("sm", { fontSize: 20 }), // if window width 0..600
  },

  // The same example that you see above but unsing a 'applyBreakpoints'
  title: {
    fontSize: breakpoints.apply({
      sm: 20, //      if window width 0....600
      lg: 18, //      if window width 601..1280
      default: 16, // if window width 1281...
    }),
  },
}));

4️⃣ Inject styles useStyles(...) & withStyles(...)

And finally just use in component:

import React, { Component } from "react";
import useStyles from "./styles";

// Functional component (hooks variant)
const Root = () => {
  const styles = useStyles();

  return <View style={styles.root} />;
};

export default Root;

//--------------------------------

// Class component (HOC variant)
class Root extends Component {
  render() {
    const { styles } = this.props;

    return <View style={styles.root} />;
  }
}

export default withStyles(useStyles)(Root);

5️⃣ Do you use a Typescript ?