Skip to content

Commit

Permalink
Move App.tsx to App.storybook.tsx and update metro config to not load…
Browse files Browse the repository at this point in the history
… storybook files when not necessary
  • Loading branch information
ACHP committed Feb 20, 2023
1 parent 8cb5b75 commit 445e483
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions App.storybook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import StorybookUIRoot from './.ondevice/Storybook';
export {StorybookUIRoot as default};
31 changes: 29 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
import StorybookUIRoot from './.ondevice/Storybook';
export {StorybookUIRoot as default};
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/

import React from 'react';
import {Button, SafeAreaView, StatusBar, useColorScheme} from 'react-native';

import {Colors} from 'react-native/Libraries/NewAppScreen';

const App: () => React.ReactNode = () => {
const isDarkMode = useColorScheme() === 'dark';

const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};

return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<Button title={'hello from RN app'} />
</SafeAreaView>
);
};

export default App;
9 changes: 8 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const {sourceExts} = require('metro-config/src/defaults/defaults');

/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const storybookSourceExt =
process.env.STORYBOOK_VARIANT === 'true'
? ['storybook.tsx', 'storybook.ts', 'storybook.js']
: [];

module.exports = {
transformer: {
Expand All @@ -15,6 +21,7 @@ module.exports = {
}),
},
resolver: {
resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'],
resolverMainFields: ['react-native', 'browser', 'main'],
sourceExts: [...storybookSourceExt, ...sourceExts],
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"start:storybook": "react-native start",
"start:storybook": "STORYBOOK_VARIANT=true react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"update-stories": "sb-rn-get-stories --config-path .ondevice",
Expand Down

0 comments on commit 445e483

Please sign in to comment.