This repository has been archived by the owner on Feb 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate portions of the drawer item implementations to the child and …
…item components DrawerNavigation{Child,Item} drawerItems are now rendered directly instead of being used as plain JS objects.
- Loading branch information
Showing
4 changed files
with
180 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,74 @@ | ||
import React from 'react'; | ||
import { | ||
StyleSheet, | ||
View, | ||
} from 'react-native'; | ||
import StaticContainer from 'react-static-container'; | ||
|
||
export type Props = { | ||
children: React.Element<any>, | ||
renderTo: 'drawer' | 'content', | ||
showsTouches: ?boolean, | ||
isSelected: boolean, | ||
selectedStyle: any, | ||
}; | ||
|
||
export default class ExNavigationDrawerChild extends React.Component { | ||
render() { | ||
props: Props; | ||
hasContent: boolean = false; | ||
|
||
renderDrawerItem() { | ||
let { children } = this.props; | ||
return React.createElement(View, null, children); | ||
} | ||
|
||
renderContent() { | ||
return null; | ||
} | ||
|
||
_renderContent() { | ||
const { isSelected } = this.props; | ||
let content = this.renderContent(); | ||
|
||
if (content === null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View | ||
removeClippedSubviews={!isSelected} | ||
style={[styles.itemContentInner, {opacity: isSelected ? 1 : 0}]} | ||
pointerEvents={isSelected ? 'auto' : 'none'}> | ||
<StaticContainer shouldUpdate={isSelected}> | ||
{content} | ||
</StaticContainer> | ||
</View> | ||
); | ||
} | ||
|
||
render() { | ||
let { renderTo } = this.props; | ||
|
||
if (renderTo === 'drawer') { | ||
return this.renderDrawerItem(); | ||
} else if (renderTo === 'content') { | ||
return this._renderContent(); | ||
} else { | ||
console.warn('renderTo must be "drawer" or "content"'); | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
itemContentOuter: { | ||
flex: 1, | ||
}, | ||
itemContentInner: { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
right: 0, | ||
bottom: 0, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,89 @@ | ||
import React from 'react'; | ||
import { | ||
TouchableWithoutFeedback, | ||
StyleSheet, | ||
View, | ||
} from 'react-native'; | ||
import TouchableNativeFeedbackSafe from '@exponent/react-native-touchable-native-feedback-safe'; | ||
import ExNavigationDrawerChild from './ExNavigationDrawerChild'; | ||
import type { Props } from './ExNavigationDrawerChild'; | ||
|
||
export default class ExNavigationDrawerItem extends ExNavigationDrawerChild { | ||
props: Props; | ||
|
||
renderDrawerItem() { | ||
let { showsTouches, isSelected, renderIcon, renderTitle, renderRight, onPress, onLongPress } = this.props; | ||
const icon = renderIcon && renderIcon(isSelected); | ||
const title = renderTitle && renderTitle(isSelected); | ||
const rightElement = renderRight && renderRight(isSelected); | ||
|
||
if (showsTouches !== false) { | ||
return ( | ||
<TouchableNativeFeedbackSafe | ||
onPress={onPress} | ||
onLongPress={onLongPress} | ||
delayPressIn={0} | ||
style={[isSelected ? this.props.selectedStyle : this.props.style]} | ||
background={this.props.nativeFeedbackBackground}> | ||
<View style={styles.buttonContainer}> | ||
{ | ||
icon && <View style={[styles.elementContainer]}>{icon}</View> | ||
} | ||
{ | ||
title && <View style={[styles.elementContainer]}>{title}</View> | ||
} | ||
{ | ||
rightElement && <View style={[styles.elementContainer, styles.rightElementContainer]}>{rightElement}</View> | ||
} | ||
</View> | ||
</TouchableNativeFeedbackSafe> | ||
); | ||
} else { | ||
return ( | ||
<TouchableWithoutFeedback | ||
onPress={onPress} | ||
onLongPress={onLongPress}> | ||
<View style={[styles.buttonContainer, isSelected ? this.props.selectedStyle : this.props.style]}> | ||
{ | ||
icon && <View style={[styles.elementContainer]}>{icon}</View> | ||
} | ||
{ | ||
title && <View style={[styles.elementContainer]}>{title}</View> | ||
} | ||
{ | ||
rightElement && <View style={[styles.elementContainer, styles.rightElementContainer]}>{rightElement}</View> | ||
} | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
} | ||
} | ||
|
||
renderContent() { | ||
if (React.Children.count(this.props.children) > 0) { | ||
return React.Children.only(this.props.children); | ||
} | ||
|
||
export default class ExNavigationDrawerItem extends React.Component { | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
buttonContainer: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
paddingVertical: 10, | ||
paddingHorizontal: 15, | ||
}, | ||
elementContainer: { | ||
flexDirection: 'row', | ||
justifyContent: 'flex-start', | ||
alignItems: 'center', | ||
}, | ||
rightElementContainer: { | ||
flex: 1, | ||
justifyContent: 'flex-end', | ||
}, | ||
}); |
Oops, something went wrong.