@@ -25,6 +25,7 @@ import { MenuItemDescriptor } from './menu.service';
25
25
26
26
export interface MenuGroupProps extends MenuItemProps {
27
27
children ?: ChildrenWithProps < MenuItemProps > ;
28
+ initiallyExpanded ?: boolean ;
28
29
}
29
30
30
31
export type MenuGroupElement = React . ReactElement < MenuGroupProps > ;
@@ -59,6 +60,9 @@ const POSITION_OUTSCREEN: Point = Point.outscreen();
59
60
* to render to end of the *title*.
60
61
* Expected to return an Image.
61
62
*
63
+ * @property {boolean } initiallyExpanded - Boolean value which defines whether group should be initially expanded.
64
+ * If true - menu group will be expanded by default.
65
+ *
62
66
* @property {TouchableOpacityProps } ...TouchableOpacityProps - Any props applied to TouchableOpacity component.
63
67
*
64
68
* @overview -example MenuGroups
@@ -68,8 +72,23 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {
68
72
public state : State = {
69
73
submenuHeight : 1 ,
70
74
} ;
75
+
76
+ private initiallyExpanded : boolean ;
77
+
71
78
private expandAnimation : Animated . Value = new Animated . Value ( 0 ) ;
72
79
80
+ constructor ( props ) {
81
+ super ( props ) ;
82
+ this . initiallyExpanded = props . initiallyExpanded ;
83
+ }
84
+
85
+ public componentDidUpdate ( prevProps : Readonly < MenuGroupProps > , prevState : Readonly < State > , snapshot ?: any ) {
86
+ const submenuHeightChanged = this . state . submenuHeight !== prevState . submenuHeight ;
87
+ if ( submenuHeightChanged && this . hasSubmenu && this . initiallyExpanded ) {
88
+ this . expandAnimation . setValue ( this . state . submenuHeight ) ;
89
+ }
90
+ }
91
+
73
92
private get hasSubmenu ( ) : boolean {
74
93
return React . Children . count ( this . props . children ) > 0 ;
75
94
}
@@ -102,6 +121,8 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {
102
121
103
122
private onPress = ( descriptor : MenuItemDescriptor , event : GestureResponderEvent ) : void => {
104
123
if ( this . hasSubmenu ) {
124
+ this . initiallyExpanded = false ;
125
+
105
126
const expandValue : number = this . expandAnimationValue > 0 ? 0 : this . state . submenuHeight ;
106
127
this . createExpandAnimation ( expandValue ) . start ( ) ;
107
128
this . props . onPress && this . props . onPress ( descriptor , event ) ;
@@ -129,7 +150,7 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {
129
150
130
151
return (
131
152
< Animated . View style = { { transform : [ { rotate : this . expandToRotateInterpolation } ] } } >
132
- < ChevronDown { ...evaProps } fill = { style . tintColor } />
153
+ < ChevronDown { ...evaProps } fill = { style . tintColor as string } />
133
154
</ Animated . View >
134
155
) ;
135
156
} ;
@@ -150,7 +171,7 @@ export class MenuGroup extends React.Component<MenuGroupProps, State> {
150
171
151
172
private renderMeasuringGroupedItems = ( evaStyle ) : MeasuringElement => {
152
173
return (
153
- < MeasureElement
174
+ < MeasureElement
154
175
shouldUseTopInsets = { ModalService . getShouldUseTopInsets }
155
176
onMeasure = { this . onSubmenuMeasure } >
156
177
{ this . renderGroupedItems ( evaStyle ) }
0 commit comments