Skip to content
This repository has been archived by the owner on Feb 15, 2019. It is now read-only.

Commit

Permalink
Use a reactElement.type prototype check instead of direct type equiva…
Browse files Browse the repository at this point in the history
…lence

This allows DrawerNavigationChild and DrawerNavigationItem to be extended with a project's patterns.
  • Loading branch information
dantman committed Mar 3, 2017
1 parent 2f29650 commit 895923c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions example/components/DrawerNavigationExample.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
Image,
} from 'react-native';
Expand All @@ -14,6 +13,14 @@ import {
import { Ionicons } from '@exponent/vector-icons';
import { Router } from '../main';

class Heading extends DrawerNavigationChild {
renderDrawerItem() {
return (
<Text style={styles.headingText}>{this.props.title}</Text>
);
}
}

export default class DrawerNavigationExample extends Component {

_renderHeader = () => {
Expand Down Expand Up @@ -69,9 +76,7 @@ export default class DrawerNavigationExample extends Component {
initialRoute={Router.getRoute('home')}
/>
</DrawerNavigationItem>
<DrawerNavigationChild>
<Text style={styles.headingText}>Meta</Text>
</DrawerNavigationChild>
<Heading title='Meta' />
<DrawerNavigationItem
id="another"
selectedStyle={styles.selectedItemStyle}
Expand Down
4 changes: 2 additions & 2 deletions src/drawer/ExNavigationDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ class ExNavigationDrawer extends PureComponent<any, Props, State> {
}

invariant(
child.type === ExNavigationDrawerItem || child.type === ExNavigationDrawerChild,
'All children of DrawerNavigation must be DrawerNavigationItems or DrawerNavigationChilds.',
child.type instanceof Object && ExNavigationDrawerChild.prototype.isPrototypeOf(child.type.prototype),
'All children of DrawerNavigation must be DrawerNavigationChild descendant components.'
);

return child;
Expand Down

0 comments on commit 895923c

Please sign in to comment.