File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
demo/src/screens/componentScreens
generatedTypes/components/expandableSection
src/components/expandableSection Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -54,14 +54,14 @@ class ExpandableSectionScreen extends PureComponent {
5454
5555 getHeaderElement ( ) {
5656 return (
57- < TouchableOpacity onPress = { ( ) => this . onExpand ( ) } >
57+ < View >
5858 < Text margin-10 dark10 text60 >
5959 ExpandableSection's sectionHeader
6060 </ Text >
6161 < View style = { styles . header } >
6262 < Image style = { styles . icon } source = { ! this . state . expanded ? chevronUp : chevronDown } />
6363 </ View >
64- </ TouchableOpacity >
64+ </ View >
6565 ) ;
6666 }
6767
@@ -84,7 +84,7 @@ class ExpandableSectionScreen extends PureComponent {
8484
8585 return (
8686 < ScrollView >
87- < ExpandableSection expanded = { expanded } sectionHeader = { this . getHeaderElement ( ) } >
87+ < ExpandableSection expanded = { expanded } sectionHeader = { this . getHeaderElement ( ) } onPress = { ( ) => this . onExpand ( ) } >
8888 { this . getBodyElement ( ) }
8989 </ ExpandableSection >
9090 < ListItem >
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export declare type ExpandableSectionProps = {
1212 * should the expandableSection be expanded
1313 */
1414 expanded ?: boolean ;
15+ /**
16+ * action for when pressing the header of the expandableSection
17+ */
18+ onPress ?: ( ) => void ;
1519} ;
1620declare function ExpandableSection ( props : ExpandableSectionProps ) : JSX . Element ;
1721export default ExpandableSection ;
Original file line number Diff line number Diff line change 11import _ from 'lodash' ;
2- import React , { useEffect } from 'react' ;
2+ import React from 'react' ;
33import { LayoutAnimation , StyleSheet } from 'react-native' ;
44import View from '../view' ;
5+ import TouchableOpacity from '../touchableOpacity'
56
67export type ExpandableSectionProps = {
78 /**
@@ -16,19 +17,23 @@ export type ExpandableSectionProps = {
1617 * should the expandableSection be expanded
1718 */
1819 expanded ?: boolean ;
20+ /**
21+ * action for when pressing the header of the expandableSection
22+ */
23+ onPress ?: ( ) => void ;
1924} ;
2025
2126function ExpandableSection ( props : ExpandableSectionProps ) {
2227 const { expanded, sectionHeader, children} = props ;
2328
24- useEffect ( ( ) => {
25- LayoutAnimation . configureNext ( { ... LayoutAnimation . Presets . easeInEaseOut , duration : 300 } ) ;
26- } , [ expanded ] ) ;
27-
29+ const onPress = ( ) => {
30+ props . onPress ?. ( ) ;
31+ LayoutAnimation . configureNext ( { ... LayoutAnimation . Presets . easeInEaseOut , duration : 300 } ) ;
32+ }
2833
2934 return (
3035 < View style = { styles . container } >
31- { sectionHeader }
36+ < TouchableOpacity onPress = { onPress } > { sectionHeader } </ TouchableOpacity >
3237 { expanded && children }
3338 </ View >
3439 ) ;
You can’t perform that action at this time.
0 commit comments