@@ -9,58 +9,58 @@ You can use dynamic expressions in `className` for conditional styling. The Babe
99
1010``` tsx
1111import { useState } from " react" ;
12- import { View , Text , Pressable } from " react-native" ;
12+ import { View , Text , TouchableOpacity } from " react-native" ;
1313
14- export function ToggleButton () {
14+ export function StatusBadge () {
1515 const [isActive, setIsActive] = useState (false );
1616
1717 return (
18- <Pressable
19- onPress = { () => setIsActive (! isActive )}
20- className = { isActive ? " bg-green-500 p-4" : " bg-red-500 p-4" }
21- >
22- <Text className = " text-white" >{ isActive ? " Active" : " Inactive" } </Text >
23- </Pressable >
18+ <TouchableOpacity onPress = { () => setIsActive (! isActive )} >
19+ <View className = { isActive ? " bg-green-500 p-4 rounded-lg" : " bg-red-500 p-4 rounded-lg" } >
20+ <Text className = " text-white font-semibold" >
21+ { isActive ? " Active" : " Inactive" }
22+ </Text >
23+ </View >
24+ </TouchableOpacity >
2425 );
2526}
2627```
2728
2829** Transforms to:**
2930
3031``` tsx
31- <Pressable
32- onPress = { () => setIsActive (! isActive )}
33- style = { isActive ? _twStyles ._bg_green_500_p_4 : _twStyles ._bg_red_500_p_4 }
34- >
35- <Text style = { _twStyles ._text_white } >{ isActive ? " Active" : " Inactive" } </Text >
36- </Pressable >
32+ <TouchableOpacity onPress = { () => setIsActive (! isActive )} >
33+ <View style = { isActive ? _twStyles ._bg_green_500_p_4_rounded_lg : _twStyles ._bg_red_500_p_4_rounded_lg } >
34+ <Text style = { _twStyles ._font_semibold_text_white } >
35+ { isActive ? " Active" : " Inactive" }
36+ </Text >
37+ </View >
38+ </TouchableOpacity >
3739```
3840
3941## Template Literals (Static + Dynamic)
4042
4143Combine static classes with dynamic conditionals:
4244
4345``` tsx
44- <Pressable
45- className = { ` border-2 rounded-lg ${isActive ? " bg-blue-500" : " bg-gray-300" } p-4 ` }
46- >
47- <Text className = " text-white" >Click Me</Text >
48- </Pressable >
46+ <View className = { ` border-2 rounded-lg ${isSelected ? " bg-blue-500" : " bg-gray-300" } p-4 ` } >
47+ <Text className = " text-white font-medium" >Card Content</Text >
48+ </View >
4949```
5050
5151** Transforms to:**
5252
5353``` tsx
54- <Pressable
54+ <View
5555 style = { [
5656 _twStyles ._border_2 ,
5757 _twStyles ._rounded_lg ,
58- isActive ? _twStyles ._bg_blue_500 : _twStyles ._bg_gray_300 ,
58+ isSelected ? _twStyles ._bg_blue_500 : _twStyles ._bg_gray_300 ,
5959 _twStyles ._p_4 ,
6060 ]}
6161>
62- <Text style = { _twStyles ._text_white } >Click Me </Text >
63- </Pressable >
62+ <Text style = { _twStyles ._font_medium_text_white } >Card Content </Text >
63+ </View >
6464```
6565
6666## Logical Expression
@@ -125,7 +125,7 @@ Here's a complete example showing multiple conditional patterns:
125125
126126``` tsx
127127import { useState } from " react" ;
128- import { View , Text , Pressable } from " react-native" ;
128+ import { View , Text , TouchableOpacity } from " react-native" ;
129129
130130export function StatusCard({ status }) {
131131 const [isExpanded, setIsExpanded] = useState (false );
@@ -140,9 +140,9 @@ export function StatusCard({ status }) {
140140 ${isExpanded ? " border-2" : " border" }
141141 ` }
142142 >
143- <Pressable onPress = { () => setIsExpanded (! isExpanded )} >
143+ <TouchableOpacity onPress = { () => setIsExpanded (! isExpanded )} >
144144 <Text className = " font-semibold" >{ status .toUpperCase ()} </Text >
145- </Pressable >
145+ </TouchableOpacity >
146146 { isExpanded && (
147147 <Text className = " mt-2 text-sm text-gray-600" >
148148 Additional details here
0 commit comments