-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVP version of the on device React Native UI
This is a combination of 10 commits. - Add a basic implementation of the native UI for the storybook - Fix the lint errors - Add a param to turn the native UI on and off using the same package - Correctly set the width of the story list - Added a size selector for the different sized iPhone screens - Show the selected story in bold - Add some styling to the panels - Removed the canvas size switcher - Fix lint errors - Shortened the long render item and header lines
- Loading branch information
1 parent
fbc665f
commit 86679eb
Showing
8 changed files
with
243 additions
and
8 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/react-native/src/preview/components/OnDeviceUI/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { PropTypes } from 'react'; | ||
import { View } from 'react-native'; | ||
import style from './style'; | ||
import StoryListView from '../StoryListView'; | ||
import StoryView from '../StoryView'; | ||
|
||
export default function OnDeviceUI(props) { | ||
const { | ||
stories, | ||
events, | ||
url | ||
} = props; | ||
|
||
return ( | ||
<View style={style.main}> | ||
<View style={style.leftPanel}> | ||
<StoryListView stories={stories} events={events} /> | ||
</View> | ||
<View style={style.rightPanel}> | ||
<View style={style.preview}> | ||
<StoryView url={url} events={events} /> | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
OnDeviceUI.propTypes = { | ||
stories: PropTypes.shape({ | ||
dumpStoryBook: PropTypes.func.isRequired, | ||
on: PropTypes.func.isRequired, | ||
emit: PropTypes.func.isRequired, | ||
removeListener: PropTypes.func.isRequired, | ||
}).isRequired, | ||
events: PropTypes.shape({ | ||
on: PropTypes.func.isRequired, | ||
emit: PropTypes.func.isRequired, | ||
removeListener: PropTypes.func.isRequired, | ||
}).isRequired, | ||
url: PropTypes.string.isRequired, | ||
}; |
28 changes: 28 additions & 0 deletions
28
app/react-native/src/preview/components/OnDeviceUI/style.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export default { | ||
main: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
paddingTop: 20, | ||
backgroundColor: 'rgba(247, 247, 247, 1)', | ||
}, | ||
leftPanel: { | ||
flex: 1, | ||
maxWidth: 250, | ||
paddingHorizontal: 8, | ||
paddingBottom: 8, | ||
}, | ||
rightPanel: { | ||
flex: 1, | ||
backgroundColor: 'rgba(255, 255, 255, 1)', | ||
borderWidth: StyleSheet.hairlineWidth, | ||
borderColor: 'rgba(236, 236, 236, 1)', | ||
borderRadius: 4, | ||
marginBottom: 8, | ||
marginHorizontal: 8, | ||
}, | ||
preview: { | ||
...StyleSheet.absoluteFillObject, | ||
}, | ||
}; |
127 changes: 127 additions & 0 deletions
127
app/react-native/src/preview/components/StoryListView/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { SectionList, View, Text, TouchableOpacity } from 'react-native'; | ||
import style from './style'; | ||
|
||
const SectionHeader = ({ title, selected }) => ( | ||
<View key={title} style={style.header}> | ||
<Text style={[style.headerText, selected && style.headerTextSelected]}> | ||
{title} | ||
</Text> | ||
</View> | ||
); | ||
|
||
SectionHeader.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
selected: PropTypes.bool.isRequired, | ||
}; | ||
|
||
const ListItem = ({ title, selected, onPress }) => ( | ||
<TouchableOpacity | ||
key={title} | ||
style={style.item} | ||
onPress={onPress} | ||
> | ||
<Text style={[style.itemText, selected && style.itemTextSelected]}> | ||
{title} | ||
</Text> | ||
</TouchableOpacity> | ||
); | ||
|
||
ListItem.propTypes = { | ||
title: PropTypes.string.isRequired, | ||
onPress: PropTypes.func.isRequired, | ||
selected: PropTypes.bool.isRequired, | ||
}; | ||
|
||
export default class StoryListView extends Component { | ||
constructor(props, ...args) { | ||
super(props, ...args); | ||
this.state = { | ||
sections: [], | ||
selectedKind: null, | ||
selectedStory: null, | ||
}; | ||
|
||
this.storyAddedHandler = this.handleStoryAdded.bind(this); | ||
this.storyChangedHandler = this.handleStoryChanged.bind(this); | ||
this.changeStoryHandler = this.changeStory.bind(this); | ||
|
||
this.props.stories.on('storyAdded', this.storyAddedHandler); | ||
this.props.events.on('story', this.storyChangedHandler); | ||
} | ||
|
||
componentDidMount() { | ||
this.handleStoryAdded(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.stories.removeListener('storyAdded', this.storiesHandler); | ||
this.props.events.removeListener('story', this.storyChangedHandler); | ||
} | ||
|
||
handleStoryAdded() { | ||
if (this.props.stories) { | ||
const data = this.props.stories.dumpStoryBook(); | ||
this.setState({ | ||
sections: data.map((section) => ({ | ||
key: section.kind, | ||
title: section.kind, | ||
data: section.stories.map((story) => ({ | ||
key: story, | ||
kind: section.kind, | ||
name: story | ||
})) | ||
})) | ||
}); | ||
} | ||
} | ||
|
||
handleStoryChanged(storyFn, selection) { | ||
const { kind, story } = selection; | ||
this.setState({ | ||
selectedKind: kind, | ||
selectedStory: story | ||
}); | ||
} | ||
|
||
changeStory(kind, story) { | ||
this.props.events.emit('setCurrentStory', { kind, story }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<SectionList | ||
style={style.list} | ||
renderItem={({ item }) => ( | ||
<ListItem | ||
title={item.name} | ||
selected={item.kind === this.state.selectedKind && item.name === this.state.selectedStory} | ||
onPress={() => this.changeStory(item.kind, item.name)} | ||
/> | ||
)} | ||
renderSectionHeader={({ section }) => ( | ||
<SectionHeader | ||
title={section.title} | ||
selected={section.title === this.state.selectedKind} | ||
/> | ||
)} | ||
sections={this.state.sections} | ||
stickySectionHeadersEnabled={false} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
StoryListView.propTypes = { | ||
stories: PropTypes.shape({ | ||
dumpStoryBook: PropTypes.func.isRequired, | ||
on: PropTypes.func.isRequired, | ||
emit: PropTypes.func.isRequired, | ||
removeListener: PropTypes.func.isRequired, | ||
}).isRequired, | ||
events: PropTypes.shape({ | ||
on: PropTypes.func.isRequired, | ||
emit: PropTypes.func.isRequired, | ||
removeListener: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; |
26 changes: 26 additions & 0 deletions
26
app/react-native/src/preview/components/StoryListView/style.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default { | ||
list: { | ||
flex: 1, | ||
maxWidth: 250, | ||
}, | ||
header: { | ||
paddingTop: 24, | ||
paddingBottom: 4, | ||
}, | ||
headerText: { | ||
fontSize: 16, | ||
}, | ||
headerTextSelected: { | ||
fontWeight: 'bold', | ||
}, | ||
item: { | ||
paddingVertical: 4, | ||
paddingHorizontal: 16, | ||
}, | ||
itemText: { | ||
fontSize: 14, | ||
}, | ||
itemTextSelected: { | ||
fontWeight: 'bold', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters