nativewind icon indicating copy to clipboard operation
nativewind copied to clipboard

Update v4-TODO.md

Open XChikuX opened this issue 2 years ago • 1 comments

Adding this as a todo. I have already made a bash script for you.

#!/bin/bash

# Check if a directory argument is provided
if [ "$#" -ne 3 ]; then
    echo "Usage: $0 <Path to project> <OriginalComponentName> <StyledComponentName>"
    exit 1
fi


# Assign arguments to variables
DIRECTORY=$1
ORIGINAL_COMPONENT=$2
STYLED_COMPONENT=$3

# Function to replace StyledComponent with OriginalComponent
replace_and_remove_styled() {
    sed -i '' \
        -e "s/$STYLED_COMPONENT/$ORIGINAL_COMPONENT/g" \
        -e "/const $ORIGINAL_COMPONENT = styled($ORIGINAL_COMPONENT);/d" \
        "$1"
    sed -i '' '/import { styled } from ['"'"'"]nativewind['"'"'"];/d' "$1"
}


# Export the function to make it available to find's exec
export -f replace_and_remove_styled

# Find all .jsx and .tsx files and apply the replacement
find "$DIRECTORY"  -maxdepth 1  -type f \( -name "*.jsx" -o -name "*.tsx" \) -exec bash -c 'replace_and_remove_styled "$0"' {} \;
find "$DIRECTORY/src" -maxdepth 5 -type f \( -name "*.jsx" -o -name "*.tsx" \) -exec bash -c 'replace_and_remove_styled "$0"' {} \;


echo "Replacement complete."

XChikuX avatar Dec 07 '23 13:12 XChikuX

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nativewind ✅ Ready (Inspect) Visit Preview Dec 7, 2023 2:00pm

vercel[bot] avatar Dec 07 '23 13:12 vercel[bot]

I do not understand what this script is going. I need to document why people no longer need styled()

marklawlor avatar Feb 13 '24 01:02 marklawlor

@marklawlor So I've used styled() extensively in my v2 nativewind code.

I needed a way to sustainably remove that function call from all of my files. This code assumes a directory structure of

/ /src

And looks for styled() in each file.

And since you will have 2 components.

Eg. const StyledView = styled(View)

It removes the above line and all instances of StyledView and replaces it with View i.e. $StyledComponent and $OriginalComponent

XChikuX avatar Feb 13 '24 07:02 XChikuX