I'm trying to find a way to make TypeScript accept passing variables to StyleSheet
Exemple:
<View style={[styles.foo(isVisible), styles.bar]} />
...
export default StyleSheet.create({
foo: (isVisible: boolean) => ({
opacity: isVisible ? 1 : 0
})
bar: {
// something
}
})
I tried to redeclare StyleSheet.create with the code below but I can't find a solution. Any idea ?
import 'react-native'
declare module 'react-native' {
namespace StyleSheet {
type Style = ViewStyle | TextStyle | ImageStyle
type NamedStyles<T> = { [P in keyof T]: Style }
export function create<T, S extends NamedStyles<S> | NamedStyles<any>>(
styles: T | NamedStyles<S>,
): T & S
}
}