Skip to content

Feat/expandable list item new component #943

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

Merged
merged 14 commits into from
Sep 25, 2020
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
3 changes: 3 additions & 0 deletions demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module.exports = {
get DrawerScreen() {
return require('./screens/componentScreens/DrawerScreen').default;
},
get ExpandableSectionScreen() {
return require('./screens/componentScreens/ExpandableSectionScreen').default;
},
get TagsInputScreen() {
return require('./screens/componentScreens/TagsInputScreen').default;
},
Expand Down
1 change: 1 addition & 0 deletions demo/src/screens/MenuStructure.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const navigationData = {
{title: 'Cards', tags: 'cards feed', screen: 'unicorn.components.CardsScreen'},
{title: 'Connection Status Bar', tags: 'connection status bar', screen: 'unicorn.components.ConnectionStatusBar'},
{title: 'Chip', tags: 'chip', screen: 'unicorn.components.ChipScreen'},
{title: 'ExpandableSection', tags: 'expandable section', screen: 'unicorn.components.ExpandableSectionScreen'},
// {title: 'Overlays', tags: 'overlay image', screen: 'unicorn.components.OverlaysScreen'},
{title: 'Page Control', tags: 'page', screen: 'unicorn.components.PageControlScreen'},
{title: 'ProgressBar', tags: 'progress bar animated', screen: 'unicorn.animations.ProgressBarScreen'},
Expand Down
112 changes: 112 additions & 0 deletions demo/src/screens/componentScreens/ExpandableSectionScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import _ from 'lodash';
import React, {PureComponent} from 'react';
import {ScrollView, StyleSheet, TouchableOpacity} from 'react-native';
import {Card, Text, Image, ListItem, Carousel, Spacings, View} from 'react-native-ui-lib';
import ExpandableSection from '../../../../src/components/expandableSection';

const cardImage2 = require('../../assets/images/empty-state.jpg');
const cardImage = require('../../assets/images/card-example.jpg');
const chevronDown = require('../../assets/icons/chevronDown.png');
const chevronUp = require('../../assets/icons/chevronUp.png');

const elements = [
<Card style={{marginBottom: 10}} onPress={() => {}}>
<Card.Section
content={[
{text: 'Card #1', text70: true, dark10: true},
{text: 'card description', text90: true, dark50: true}
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
</Card>,
<Card style={{marginBottom: 10}} onPress={() => {}}>
<Card.Section
content={[
{text: 'Card #2', text70: true, dark10: true},
{text: 'card description', text90: true, dark50: true}
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage} imageStyle={{height: 120}} />
</Card>,
<Card style={{marginBottom: 10}} onPress={() => {}}>
<Card.Section
content={[
{text: 'Card #3', text70: true, dark10: true},
{text: 'card description', text90: true, dark50: true}
]}
style={{padding: 20}}
/>
<Card.Section imageSource={cardImage2} imageStyle={{height: 120}} />
</Card>
];

class ExpandableSectionScreen extends PureComponent {
state = {
expanded: false
};

onExpand() {
this.setState({
expanded: !this.state.expanded
});
}

getHeaderElement() {
return (
<TouchableOpacity onPress={() => this.onExpand()}>
<Text margin-10 dark10 text60>
ExpandableSection's sectionHeader
</Text>
<View style={styles.header}>
<Image style={styles.icon} source={!this.state.expanded ? chevronUp : chevronDown} />
</View>
</TouchableOpacity>
);
}

getBodyElement() {
return (
<Carousel pageWidth={350} itemSpacings={Spacings.s2}>
{_.map(elements, (element, key) => {
return (
<View key={key} margin-12>
{element}
</View>
);
})}
</Carousel>
);
}

render() {
const {expanded} = this.state;

return (
<ScrollView>
<ExpandableSection expanded={expanded} sectionHeader={this.getHeaderElement()}>
{this.getBodyElement()}
</ExpandableSection>
<ListItem>
<Text dark10 text60 marginL-10>
{'The next item'}
</Text>
</ListItem>
</ScrollView>
);
}
}

export default ExpandableSectionScreen;

const styles = StyleSheet.create({
header: {
marginLeft: 380,
marginTop: 20,
position: 'absolute'
},
icon: {
backgroundColor: 'transparent'
}
});
1 change: 1 addition & 0 deletions demo/src/screens/componentScreens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function registerScreens(registrar) {
registrar('unicorn.components.ConnectionStatusBar', () => require('./ConnectionStatusBarScreen').default);
registrar('unicorn.components.DialogScreen', () => require('./DialogScreen').default);
registrar('unicorn.components.DrawerScreen', () => require('./DrawerScreen').default);
registrar('unicorn.components.ExpandableSectionScreen', () => require('./ExpandableSectionScreen').default);
registrar('unicorn.components.TagsInputScreen', () => require('./TagsInputScreen').default);
registrar('unicorn.components.HintsScreen', () => require('./HintsScreen').default);
registrar('unicorn.components.ImageScreen', () => require('./ImageScreen').default);
Expand Down
84 changes: 0 additions & 84 deletions expoDemo/android/gradlew.bat

This file was deleted.

13 changes: 13 additions & 0 deletions generatedTypes/components/expandableListItem/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="react" />
export declare type ExpandableSectionProps = {
/**
* ExpandableSection text element
*/
textElement?: JSX.Element;
/**
* ExpandableSection icon color
*/
iconColor?: string;
};
declare function ExpandableSection(props: ExpandableSectionProps): JSX.Element;
export default ExpandableSection;
17 changes: 17 additions & 0 deletions generatedTypes/components/expandableSection/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
export declare type ExpandableSectionProps = {
/**
* expandableSection header element
*/
sectionHeader?: JSX.Element;
/**
* expandableSection expandable children
*/
children?: React.ReactNode;
/**
* should the expandableSection be expanded
*/
expanded?: boolean;
};
declare function ExpandableSection(props: ExpandableSectionProps): JSX.Element;
export default ExpandableSection;
2 changes: 2 additions & 0 deletions generatedTypes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {default as RadioButton, RadioButtonPropTypes} from './components/radioBu
export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButton/RadioGroup';
export {default as TabBar} from './components/TabBar';
export {default as Fader, FaderProps, FaderPosition} from './components/fader';
export {default as ExpandableSection, ExpandableSectionProps } from './components/ExpandableSection';
export {default as Modal, ModalProps, ModalTopBarProps} from './components/modal';
export {default as PanGestureView, PanGestureViewProps} from './components/panningViews/panGestureView';
export {default as PanningContext} from './components/panningViews/panningContext';
Expand Down Expand Up @@ -48,6 +49,7 @@ export {
ConnectionStatusBar,
Dialog,
Drawer,
ExpandableSection,
FeatureHighlight,
Hint,
BaseInput,
Expand Down
43 changes: 43 additions & 0 deletions src/components/expandableSection/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import _ from 'lodash';
import React, {useEffect} from 'react';
import {LayoutAnimation, StyleSheet} from 'react-native';
import View from '../view';

export type ExpandableSectionProps = {
/**
* expandableSection header element
*/
sectionHeader?: JSX.Element;
/**
* expandableSection expandable children
*/
children?: React.ReactNode;
/**
* should the expandableSection be expanded
*/
expanded?: boolean;
};

function ExpandableSection(props: ExpandableSectionProps) {
const {expanded, sectionHeader, children} = props;

useEffect(() => {
LayoutAnimation.configureNext({...LayoutAnimation.Presets.easeInEaseOut, duration: 300});
}, [expanded]);


return (
<View style={styles.container}>
{sectionHeader}
{expanded && children}
</View>
);
}

export default ExpandableSection;

const styles = StyleSheet.create({
container: {
overflow: 'hidden'
}
});
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default {
get Drawer() {
return require('./components/drawer').default;
},
get ExpandableSection() {
return require('./components/expandableSection').default;
},
get Fader() {
return require('./components/fader').default;
},
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export {default as RadioButton, RadioButtonPropTypes} from './components/radioBu
export {default as RadioGroup, RadioGroupPropTypes} from './components/radioButton/RadioGroup';
export {default as TabBar} from './components/TabBar';
export {default as Fader, FaderProps, FaderPosition} from './components/fader';
export {default as ExpandableSection, ExpandableSectionProps} from './components/expandableSection';
export {default as Modal, ModalProps, ModalTopBarProps} from './components/modal';
export {default as PanGestureView, PanGestureViewProps} from './components/panningViews/panGestureView';
export {default as PanningContext} from './components/panningViews/panningContext';
Expand Down