Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Show a help text on device #111

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/preview/components/StoryView/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { View } from 'react-native';
import { View, Text } from 'react-native';
import style from './style';

export default class StoryView extends Component {
Expand All @@ -13,9 +13,19 @@ export default class StoryView extends Component {
this.setState({storyFn, selection});
}

renderHelp() {
return (
<View style={style.help}>
{this.props.url
? <Text>Please open the Storybook UI ({this.props.url}) with a web browser and select a story for preview.</Text>
: <Text>Please open the Storybook UI with a web browser and select a story for preview.</Text>}
</View>
);
}

render() {
if (!this.state.storyFn) {
return null;
return this.renderHelp();
}
const { kind, story } = this.state.selection;
const context = { kind, story };
Expand Down
6 changes: 6 additions & 0 deletions src/preview/components/StoryView/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ export default {
main: {
flex: 1,
},
help: {
flex: 1,
padding: 15,
alignItems: 'center',
justifyContent: 'center',
},
};
4 changes: 3 additions & 1 deletion src/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ export default class Preview {

getStorybookUI(params = {}) {
return () => {
let webUrl = null;
let channel = addons.getChannel();
if (!channel) {
const host = params.host || 'localhost';
const port = params.port || 7007;
const url = `ws://${host}:${port}`;
webUrl = `http://${host}:${port}`;
channel = createChannel({ url });
addons.setChannel(channel);
}
Expand All @@ -67,7 +69,7 @@ export default class Preview {
this._sendSetStories();
this._sendGetCurrentStory();
// finally return the preview component
return <StoryView events={this._events} />;
return <StoryView url={webUrl} events={this._events} />;
}
}

Expand Down