diff --git a/src/drawer/ExNavigationDrawerLayout.js b/src/drawer/ExNavigationDrawerLayout.js index d4210a3..4d24ab3 100644 --- a/src/drawer/ExNavigationDrawerLayout.js +++ b/src/drawer/ExNavigationDrawerLayout.js @@ -10,9 +10,19 @@ import { } from 'react-native'; import DrawerLayout from 'react-native-drawer-layout'; +type NavigationViewOptions = { + renderHeader: () => React.Element, + renderDrawerItems: (items: Array>) => Array>, + items: Array>, + containerStyle: Array, + scrollableContentContainerStyle: Array, +}; + type Props = { renderHeader: () => React.Element, + renderNavigationView: (options:NavigationViewOptions) => React.Element, width: number, + items: Array>, children: React.Element, drawerBackgroundColor: string, drawerPosition: 'left' | 'right', @@ -41,7 +51,7 @@ export default class ExNavigationDrawerLayout extends React.Component { drawerBackgroundColor={this.props.drawerBackgroundColor} drawerWidth={this.props.width} drawerPosition={DrawerLayout.positions[position]} - renderNavigationView={this.props.renderNavigationView || this._renderNavigationView}> + renderNavigationView={this._renderNavigationView}> {this.props.children} ); @@ -56,25 +66,36 @@ export default class ExNavigationDrawerLayout extends React.Component { } _renderNavigationView = () => { + const renderNavigationView = this.props.renderNavigationView || this.renderNavigationView; + return renderNavigationView({ + renderHeader: this.props.renderHeader, + renderDrawerItems: this.renderDrawerItems, + items: this.props.items, + containerStyle: [styles.navigationViewContainer, this.props.style], + scrollableContentContainerStyle: [styles.navigationViewScrollableContentContainer], + }); + } + + renderNavigationView = ({renderHeader, renderDrawerItems, items, containerStyle, scrollableContentContainerStyle}:NavigationViewOptions) => { return ( - + - {this.props.renderHeader()} + {renderHeader()} - - {this._renderDrawerItems()} + + {renderDrawerItems(items)} ); } - _renderDrawerItems = () => { - if (!this.props.items) { - return null; + renderDrawerItems = (items: Array>) => { + if (!items) { + return []; } - return this.props.items.map((item, index) => { + return items.map((item, index) => { let isSelected = this.props.selectedItem === item.props.id; return React.cloneElement(item, {