-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
fix: Add sections to onChange props #260
base: master
Are you sure you want to change the base?
Conversation
example source code. const list = [
{
path: '',
image: '',
title: '',
subMenuList: [
{
path: '',
title: '',
uri: '',
},
{
path: '',
title: '',
uri: '',
},
],
},
];
...
export class SubMenuContents extends Component<Props> {
state = {
activeSections: [],
activeSubSections: [],
};
onNestSection = (activeSections, sections) => {
const activeMenu = sections[activeSections];
goTo(activeMenu.path, { uri: activeMenu.uri });
};
setSections = (activeSections: $index[]) => {
const { list } = this.props;
this.setState({ activeSections });
const pressMenu = activeSections.length ?
list[activeSections] :
list[this.state.activeSections];
goTo(pressMenu.path, { uri: pressMenu.uri });
};
_render = (section) => {
const { image, title } = section;
return (
<MenuItem title={title} image={image} />
);
};
renderHeader = section => {
return this._render(section);
};
renderContent = section => {
if ('subMenuList' in section) {
return (
<Accordion
sections={section.subMenuList}
activeSections={this.state.activeSubSections}
renderSectionTitle={() => <View />}
renderHeader={this.renderHeader}
renderContent={this.renderContent}
onChange={this.onNestSection}
touchableComponent={TouchableOpacity}
/>
);
}
return <View />;
};
render() {
const { list } = this.props;
return (
<Accordion
sections={list}
activeSections={this.state.activeSections}
renderSectionTitle={() => <View />}
renderHeader={this.renderHeader}
renderContent={this.renderContent}
onChange={this.setSections}
touchableComponent={TouchableOpacity}
/>
);
}
} |
@iRoachie how is it? |
Correct me if I'm wrong. The react-native-collapsible/Accordion.js Line 76 in 2fd64a8
|
@iRoachie First we tried to use an already existing const list = [
{ title: 'A' },
{
title: 'B',
subList: [{ title: 'B-1' }, { title: 'B-2' } ],
},
]; The result... master branch:
The result I would like is... this PR:
The reason is that I make the following reference. master branch:
this PR:
|
Can you make a quick snack on http://snack.expo.io that i could test this with? I'll copy it locally and then use your branch/changes. |
@iRoachie |
After I apply your change, how would the example change to be able to get the information for the sublist? |
@iRoachie |
I think this is a change that should be merged soon. |
When I tried to create a menu component using Accordion, I attempted to implement Accordion in Accordion.
The use case is below.
onChange
(onPress)onChange
(index)onChange
In such a case, you can not distinguish nested menus with the onChange index alone.
So, we added
sections
to props ononChange
.This section represents sections in the same hierarchy as
onChange
.I thought that this problem can be implemented if we use
<Collapsible>
without using<Accordion>
. However, in that case I thought that it was redundant, implementing a feature like<Accordion>
in<Collapsible>
.I feel that adding the above props is smartest, but what about it?