-
-
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.
Add a basic implementation of the native UI for the storybook
- Loading branch information
1 parent
33096d4
commit 2fe3e8c
Showing
5 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
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,90 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { SectionList, View, Text, TouchableHighlight } from 'react-native'; | ||
import style from './style'; | ||
|
||
const SectionHeader = ({ title }) => { | ||
return ( | ||
<View key={title} style={style.header}> | ||
<Text style={style.headerText}> | ||
{title} | ||
</Text> | ||
</View> | ||
) | ||
} | ||
|
||
const ListItem = ({ title, onPress }) => { | ||
return ( | ||
<TouchableHighlight | ||
key={title} | ||
style={style.item} | ||
onPress={onPress} | ||
> | ||
<Text style={style.itemText}> | ||
{title} | ||
</Text> | ||
</TouchableHighlight> | ||
) | ||
} | ||
|
||
export default class StoryListView extends Component { | ||
constructor(props, ...args) { | ||
super(props, ...args); | ||
this.state = { stories: {} }; | ||
|
||
this.storiesHandler = this.handleStoryAdded.bind(this); | ||
this.setStoryHandler = this.handleSetStory.bind(this); | ||
|
||
this.props.stories.on('storyAdded', this.storiesHandler); | ||
} | ||
|
||
componentDidMount() { | ||
this.storiesHandler(); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.stories.removeListener('storyAdded', this.storiesHandler); | ||
} | ||
|
||
handleStoryAdded() { | ||
const data = this.props.stories.dumpStoryBook(); | ||
this.setState({ | ||
sections: data.map((section) => { | ||
return { | ||
key: section.kind, | ||
title: section.kind, | ||
data: section.stories.map((story) => { | ||
return { | ||
key: story, | ||
kind: section.kind, | ||
name: story | ||
} | ||
}) | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
handleSetStory(kind, story) { | ||
this.props.events.emit('setCurrentStory', { kind, story }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<SectionList | ||
style={style.list} | ||
renderItem={({ item }) => <ListItem title={item.name} onPress={() => this.setStoryHandler(item.kind, item.name)} />} | ||
renderSectionHeader={({ section }) => <SectionHeader title={section.title} />} | ||
sections={this.state.sections || []} | ||
stickySectionHeadersEnabled={false} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
StoryListView.propTypes = { | ||
stories: PropTypes.any.isRequired, | ||
events: PropTypes.shape({ | ||
on: PropTypes.func.isRequired, | ||
removeListener: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
export default { | ||
list: { | ||
flex: 1, | ||
}, | ||
header: { | ||
paddingTop: 24, | ||
paddingBottom: 4, | ||
paddingHorizontal: 16, | ||
}, | ||
headerText: { | ||
fontWeight: 'bold', | ||
}, | ||
item: { | ||
paddingVertical: 4, | ||
paddingHorizontal: 16, | ||
}, | ||
itemText: { | ||
|
||
}, | ||
}; |
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