Skip to content
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
1 change: 1 addition & 0 deletions app/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"json-loader": "^0.5.4",
"json5": "^0.5.1",
"postcss-loader": "^2.0.5",
"react-native-compat": "0.0.2",
"shelljs": "^0.7.8",
"style-loader": "^0.17.0",
"url-loader": "^0.5.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet } from 'react-native';
import { StyleSheet } from 'react-native-compat';

export default {
main: {
Expand Down
67 changes: 40 additions & 27 deletions app/react-native/src/preview/components/StoryListView/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component, PropTypes } from 'react';
import { SectionList, View, Text, TouchableOpacity } from 'react-native';
import { ListView, View, Text, TouchableOpacity } from 'react-native';
import { MinMaxView } from 'react-native-compat';
import style from './style';

const SectionHeader = ({ title, selected }) =>
Expand Down Expand Up @@ -30,8 +31,14 @@ ListItem.propTypes = {
export default class StoryListView extends Component {
constructor(props, ...args) {
super(props, ...args);

const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2,
});

this.state = {
sections: [],
dataSource: ds.cloneWithRowsAndSections({}),
};

this.storyAddedHandler = this.handleStoryAdded.bind(this);
Expand All @@ -56,16 +63,20 @@ export default class StoryListView extends Component {
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 => ({

const sections = data.reduce(
(map, section) => ({
...map,
[section.kind]: section.stories.map(story => ({
key: story,
kind: section.kind,
name: story,
kind: section.kind,
})),
})),
}),
{}
);
this.setState({
dataSource: this.state.dataSource.cloneWithRowsAndSections(sections),
});
}
}
Expand All @@ -76,24 +87,26 @@ export default class StoryListView extends Component {

render() {
return (
<SectionList
style={style.list}
renderItem={({ item }) =>
<ListItem
title={item.name}
selected={
item.kind === this.props.selectedKind && item.name === this.props.selectedStory
}
onPress={() => this.changeStory(item.kind, item.name)}
/>}
renderSectionHeader={({ section }) =>
<SectionHeader
title={section.title}
selected={section.title === this.props.selectedKind}
/>}
sections={this.state.sections}
stickySectionHeadersEnabled={false}
/>
<MinMaxView maxWidth={250}>
<ListView
style={style.list}
renderRow={item =>
<ListItem
title={item.name}
selected={
item.kind === this.props.selectedKind && item.name === this.props.selectedStory
}
onPress={() => this.changeStory(item.kind, item.name)}
/>}
renderSectionHeader={(sectionData, sectionName) =>
<SectionHeader
title={sectionName}
selected={sectionName === this.props.selectedKind}
/>}
dataSource={this.state.dataSource}
stickySectionHeadersEnabled={false}
/>
</MinMaxView>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default {
list: {
flex: 1,
maxWidth: 250,
},
header: {
paddingTop: 4,
Expand Down