-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the RN packager's host by default #1568
Changes from all commits
aebecbe
8f10fce
279dc89
67a7093
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
/* eslint no-underscore-dangle: 0 */ | ||
|
||
import React from 'react'; | ||
import { NativeModules } from 'react-native'; | ||
import parse from 'url-parse'; | ||
import addons from '@storybook/addons'; | ||
import createChannel from '@storybook/channel-websocket'; | ||
import { EventEmitter } from 'events'; | ||
|
@@ -55,8 +57,7 @@ export default class Preview { | |
let webUrl = null; | ||
let channel = addons.getChannel(); | ||
if (params.resetStorybook || !channel) { | ||
const host = params.host || 'localhost'; | ||
|
||
const host = params.host || parse(NativeModules.SourceCode.scriptURL).hostname; | ||
const port = params.port !== false ? `:${params.port || 7007}` : ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the port for the ReactNative packager? Or where storybooks web previewed will be binding to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the storybook port |
||
|
||
const query = params.query || ''; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": ["babel-preset-expo"], | ||
"env": { | ||
"development": { | ||
"plugins": ["transform-react-jsx-source"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
[ignore] | ||
; We fork some components by platform | ||
.*/*[.]android.js | ||
|
||
; Ignore "BUCK" generated dirs | ||
<PROJECT_ROOT>/\.buckd/ | ||
|
||
; Ignore unexpected extra "@providesModule" | ||
.*/node_modules/.*/node_modules/fbjs/.* | ||
|
||
; Ignore duplicate module providers | ||
; For RN Apps installed via npm, "Libraries" folder is inside | ||
; "node_modules/react-native" but in the source repo it is in the root | ||
.*/Libraries/react-native/React.js | ||
.*/Libraries/react-native/ReactNative.js | ||
|
||
; Additional create-react-native-app ignores | ||
|
||
; Ignore duplicate module providers | ||
.*/node_modules/fbemitter/lib/* | ||
|
||
; Ignore misbehaving dev-dependencies | ||
.*/node_modules/xdl/build/* | ||
.*/node_modules/reqwest/tests/* | ||
|
||
; Ignore missing expo-sdk dependencies (temporarily) | ||
; https://github.com/expo/expo/issues/162 | ||
.*/node_modules/expo/src/* | ||
|
||
; Ignore react-native-fbads dependency of the expo sdk | ||
.*/node_modules/react-native-fbads/* | ||
|
||
[include] | ||
|
||
[libs] | ||
node_modules/react-native/Libraries/react-native/react-native-interface.js | ||
node_modules/react-native/flow | ||
flow/ | ||
|
||
[options] | ||
module.system=haste | ||
|
||
emoji=true | ||
|
||
experimental.strict_type_args=true | ||
|
||
munge_underscores=true | ||
|
||
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' | ||
|
||
suppress_type=$FlowIssue | ||
suppress_type=$FlowFixMe | ||
suppress_type=$FixMe | ||
|
||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\) | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+ | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy | ||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError | ||
|
||
unsafe.enable_getters_and_setters=true | ||
|
||
[version] | ||
^0.47.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.expo/ | ||
npm-debug.* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default from './storybook'; | ||
|
||
// NOTE: The code below is what CRNA generates out of the box. We currently | ||
// have no clever way of replacing this with Storybook's UI (Vanilla RN does!) | ||
// so for now we just replace the code outright. Keeping this here for clarity. | ||
// | ||
// import React from 'react'; | ||
// import { StyleSheet, Text, View } from 'react-native'; | ||
// | ||
// export default class App extends React.Component { | ||
// render() { | ||
// return ( | ||
// <View style={styles.container}> | ||
// <Text>Open up App.js to start working on your app!</Text> | ||
// <Text>Changes you make will automatically reload.</Text> | ||
// <Text>Shake your phone to open the developer menu.</Text> | ||
// </View> | ||
// ); | ||
// } | ||
// } | ||
// | ||
// const styles = StyleSheet.create({ | ||
// container: { | ||
// flex: 1, | ||
// backgroundColor: '#fff', | ||
// alignItems: 'center', | ||
// justifyContent: 'center', | ||
// }, | ||
// }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import renderer from 'react-test-renderer'; | ||
|
||
import React from 'react'; | ||
import App from './App'; | ||
|
||
it('renders without crashing', () => { | ||
const rendered = renderer.create(<App />).toJSON(); | ||
expect(rendered).toBeTruthy(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# CRNA Kitchen Sink | ||
|
||
This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app) and storybook using [getstorybook](https://www.npmjs.com/package/@storybook/cli). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"expo": { | ||
"sdkVersion": "19.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "crna-kitchen-sink", | ||
"version": "0.1.0", | ||
"private": true, | ||
"devDependencies": { | ||
"@storybook/addon-actions": "file:../../addons/actions", | ||
"@storybook/addon-links": "file:../../addons/links", | ||
"@storybook/addon-options": "file:../../addons/options", | ||
"@storybook/addon-storyshots": "file:../../addons/storyshots", | ||
"@storybook/addons": "file:../../lib/addons", | ||
"@storybook/channels": "file:../../lib/channels", | ||
"@storybook/channel-postmessage": "file:../../lib/channel-postmessage", | ||
"@storybook/react-native": "file:../../app/react-native", | ||
"@storybook/ui": "file:../../lib/ui", | ||
"react-native-scripts": "1.1.0", | ||
"jest-expo": "~19.0.0", | ||
"react-test-renderer": "16.0.0-alpha.12" | ||
}, | ||
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", | ||
"scripts": { | ||
"start": "react-native-scripts start", | ||
"eject": "react-native-scripts eject", | ||
"android": "react-native-scripts android", | ||
"ios": "react-native-scripts ios", | ||
"test": "node node_modules/jest/bin/jest.js --watch", | ||
"storybook": "storybook start -p 7007" | ||
}, | ||
"jest": { | ||
"preset": "jest-expo" | ||
}, | ||
"dependencies": { | ||
"expo": "^19.0.0", | ||
"react": "16.0.0-alpha.12", | ||
"react-native": "^0.46.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import '@storybook/addon-actions/register'; | ||
import '@storybook/addon-links/register'; | ||
import '@storybook/addon-options/register'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getStorybookUI, configure } from '@storybook/react-native'; | ||
import { setOptions } from '@storybook/addon-options'; | ||
|
||
// import stories | ||
configure(() => { | ||
// eslint-disable-next-line global-require | ||
require('./stories'); | ||
}, module); | ||
|
||
const StorybookUI = getStorybookUI({ | ||
port: 7007, | ||
onDeviceUI: true, | ||
}); | ||
|
||
setTimeout( | ||
() => | ||
setOptions({ | ||
name: 'CRNA React Native App', | ||
onDeviceUI: true, | ||
}), | ||
100 | ||
); | ||
|
||
export default StorybookUI; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { TouchableNativeFeedback } from 'react-native'; | ||
|
||
export default function Button(props) { | ||
return ( | ||
<TouchableNativeFeedback onPress={props.onPress}> | ||
{props.children} | ||
</TouchableNativeFeedback> | ||
); | ||
} | ||
|
||
Button.defaultProps = { | ||
children: null, | ||
onPress: () => {}, | ||
}; | ||
|
||
Button.propTypes = { | ||
children: PropTypes.node, | ||
onPress: PropTypes.func, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { TouchableHighlight } from 'react-native'; | ||
|
||
export default function Button(props) { | ||
return ( | ||
<TouchableHighlight onPress={props.onPress}> | ||
{props.children} | ||
</TouchableHighlight> | ||
); | ||
} | ||
|
||
Button.defaultProps = { | ||
children: null, | ||
onPress: () => {}, | ||
}; | ||
|
||
Button.propTypes = { | ||
children: PropTypes.node, | ||
onPress: PropTypes.func, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { View } from 'react-native'; | ||
import style from './style'; | ||
|
||
export default function CenterView(props) { | ||
return ( | ||
<View style={style.main}> | ||
{props.children} | ||
</View> | ||
); | ||
} | ||
|
||
CenterView.defaultProps = { | ||
children: null, | ||
}; | ||
|
||
CenterView.propTypes = { | ||
children: PropTypes.node, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
main: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */ | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { View, Text } from 'react-native'; | ||
|
||
export default class Welcome extends React.Component { | ||
styles = { | ||
wrapper: { | ||
flex: 1, | ||
padding: 24, | ||
justifyContent: 'center', | ||
}, | ||
header: { | ||
fontSize: 18, | ||
marginBottom: 18, | ||
}, | ||
content: { | ||
fontSize: 12, | ||
marginBottom: 10, | ||
lineHeight: 18, | ||
}, | ||
}; | ||
|
||
showApp(event) { | ||
event.preventDefault(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive my ignorance, but why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copypasta? i'm not sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also unsureFWIW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's all over the code (part of the CLI boilerplate), so I propose we address it separately 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do not typically need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. although - this might be something CRNA related so if so, please ignore my thoughts on removing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK OK looks like it isn't used so I'll remove across the board, test, and submit. Thanks 🙇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On third thought, I think this is a separate issue. This used to be used to show off |
||
if (this.props.showApp) this.props.showApp(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={this.styles.wrapper}> | ||
<Text style={this.styles.header}>Welcome to React Native Storybook</Text> | ||
<Text style={this.styles.content}> | ||
This is a UI Component development environment for your React Native app. Here you can | ||
display and interact with your UI components as stories. A story is a single state of one | ||
or more UI components. You can have as many stories as you want. In other words a story is | ||
like a visual test case. | ||
</Text> | ||
<Text style={this.styles.content}> | ||
We have added some stories inside the "storybook/stories" directory for examples. Try | ||
editing the "storybook/stories/Welcome.js" file to edit this message. | ||
</Text> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
Welcome.defaultProps = { | ||
showApp: null, | ||
}; | ||
|
||
Welcome.propTypes = { | ||
showApp: PropTypes.func, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { Text } from 'react-native'; | ||
|
||
import { storiesOf } from '@storybook/react-native'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { linkTo } from '@storybook/addon-links'; | ||
|
||
import Button from './Button'; | ||
import CenterView from './CenterView'; | ||
import Welcome from './Welcome'; | ||
|
||
storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />); | ||
|
||
storiesOf('Button', module) | ||
.addDecorator(getStory => | ||
<CenterView> | ||
{getStory()} | ||
</CenterView> | ||
) | ||
.add('with text', () => | ||
<Button onPress={action('clicked-text')}> | ||
<Text>Hello Button</Text> | ||
</Button> | ||
) | ||
.add('with some emoji', () => | ||
<Button onPress={action('clicked-emoji')}> | ||
<Text>😀 😎 👍 💯</Text> | ||
</Button> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant - didn’t know this was an accessible thing