Is there a way to pass the pressed
property to styled-components?
What I have now:
import React from 'react';
import { Pressable, Text, View } from 'react-native';
import styled from 'styled-components/native';
const StyledPressable = styled(Pressable)``;
const App = () => {
return (
<View>
<StyledPressable
onPress={() => null}
android_ripple={{ color: 'black', borderless: true }}>
<Text>Log in</Text>
</StyledPressable>
</View>
);
};
export default App;
What I want to achieve
import React from 'react';
import { Pressable, Text, View } from 'react-native';
import styled from 'styled-components/native';
const StyledPressable = styled(Pressable)`
background-color: ${props => pressed ? 'black' : 'blue'} // change color on press, eg.
`;
const App = () => {
return (
<View>
<StyledPressable
onPress={() => null}
android_ripple={{ color: 'black', borderless: true }}>
pressed={pressed} // this property "pressed" does not exist.
<Text>Log in</Text>
</StyledPressable>
</View>
);
};
export default App;
This is the official docs. It uses inline style and I can't make this work with styled components.