UNPKG

@storybook/addon-ondevice-backgrounds

Version:

A react-native storybook addon to show different backgrounds for your preview

19 lines (18 loc) 830 B
import { jsx as _jsx } from "react/jsx-runtime"; import { useState, useEffect } from 'react'; import { StyleSheet, View } from 'react-native'; import Constants from './constants'; const Container = ({ initialBackground, channel, children }) => { const [background, setBackground] = useState(initialBackground || ''); useEffect(() => { channel.on(Constants.UPDATE_BACKGROUND, setBackground); return () => { channel.removeListener(Constants.UPDATE_BACKGROUND, setBackground); }; }, [channel]); return (_jsx(View, { testID: "addon-backgrounds-container", style: [styles.container, background && { backgroundColor: background }], children: children })); }; export default Container; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'transparent' }, });