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-tailwind-rn

v2.0.3

Published

Allows you to use className='w-full md:w-1/2' syntax in your react native projects.

Downloads

68

Readme

React Native Tailwind CSS v2

When a babel plugin, and react hook has a baby. You end up with this! A way that allows you to use Tailwind CSS within your React Native project via the familiar className property!

Changes since v1

The architecture around v1 focused on using hooks within each component, however React doesn't support a dynamic number of hooks, which means if the number or rows, views etc changed it would throw an error.

The internals for the react side of v2 have been changed to an HOC which stores the state only once, then passes it down to each component by wrapping your layout level component (often the App) with our useTailwind function.

Installation

  • yarn add babel-plugin-tailwind-rn

  • babel.config.js add the plugin tailwind-rn e.g. plugins: ['tailwind-rn']

Usage

When Metro/Webpack boots up, it runs your apps javascript through babel.

We hook into this process converting your className="text-xl" props into style={useTailwind("text-xl")}

This means we're able to add listeners on the resize events and dynamically update your styles based off the responsive Tailwind classes.

To provide your components with the correct classes, you'll need to wrap your App with our HOC, this is your root-most component.

import useTailwind from 'babel-plugin-tailwind-rn/dist/useTailwind'

function App() {
    return <Text>My Tailwind App!</Text>
}

export default useTailwind(App)

Then use the normal react syntax!

function App() {
    return <Text className="text-md lg:text-xl">My Tailwind App!</Text>
}

Important Notes

Updating Config

Metro uses heavy caching to speed up your builds, this means it holds your tailwind config in memory on the device/simulator.

Once you've made changes to your tailwind.config.js You need to clear the metro cache, often with shift + r which reloads with fresh cache.

However that only refreshes the webpack cache, you now need to exit the RN app on the simulator/device, and then relaunch the app. Metro allows you to push i or a to launch it again.

Example Project

You can download an example project which uses Expo to see how it works

https://github.com/OwenMelbz/tailwind-rn-example

Disclaimer

Code heavily influenced from: https://github.com/vadimdemedes/tailwind-rn as well as some glorious copy/paste of the class validation utilities!

Also thanks to Brad from Discord... I don't know who you are, or where you came from. But thanks for Babel support!