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 {
54
54
55
55
getHeaderElement ( ) {
56
56
return (
57
- < TouchableOpacity onPress = { ( ) => this . onExpand ( ) } >
57
+ < View >
58
58
< Text margin-10 dark10 text60 >
59
59
ExpandableSection's sectionHeader
60
60
</ Text >
61
61
< View style = { styles . header } >
62
62
< Image style = { styles . icon } source = { ! this . state . expanded ? chevronUp : chevronDown } />
63
63
</ View >
64
- </ TouchableOpacity >
64
+ </ View >
65
65
) ;
66
66
}
67
67
@@ -84,7 +84,7 @@ class ExpandableSectionScreen extends PureComponent {
84
84
85
85
return (
86
86
< ScrollView >
87
- < ExpandableSection expanded = { expanded } sectionHeader = { this . getHeaderElement ( ) } >
87
+ < ExpandableSection expanded = { expanded } sectionHeader = { this . getHeaderElement ( ) } onPress = { ( ) => this . onExpand ( ) } >
88
88
{ this . getBodyElement ( ) }
89
89
</ ExpandableSection >
90
90
< ListItem >
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export declare type ExpandableSectionProps = {
12
12
* should the expandableSection be expanded
13
13
*/
14
14
expanded ?: boolean ;
15
+ /**
16
+ * action for when pressing the header of the expandableSection
17
+ */
18
+ onPress ?: ( ) => void ;
15
19
} ;
16
20
declare function ExpandableSection ( props : ExpandableSectionProps ) : JSX . Element ;
17
21
export default ExpandableSection ;
Original file line number Diff line number Diff line change 1
1
import _ from 'lodash' ;
2
- import React , { useEffect } from 'react' ;
2
+ import React from 'react' ;
3
3
import { LayoutAnimation , StyleSheet } from 'react-native' ;
4
4
import View from '../view' ;
5
+ import TouchableOpacity from '../touchableOpacity'
5
6
6
7
export type ExpandableSectionProps = {
7
8
/**
@@ -16,19 +17,23 @@ export type ExpandableSectionProps = {
16
17
* should the expandableSection be expanded
17
18
*/
18
19
expanded ?: boolean ;
20
+ /**
21
+ * action for when pressing the header of the expandableSection
22
+ */
23
+ onPress ?: ( ) => void ;
19
24
} ;
20
25
21
26
function ExpandableSection ( props : ExpandableSectionProps ) {
22
27
const { expanded, sectionHeader, children} = props ;
23
28
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
+ }
28
33
29
34
return (
30
35
< View style = { styles . container } >
31
- { sectionHeader }
36
+ < TouchableOpacity onPress = { onPress } > { sectionHeader } </ TouchableOpacity >
32
37
{ expanded && children }
33
38
</ View >
34
39
) ;
You can’t perform that action at this time.
0 commit comments