Force rerendering Hamburger icon when clicking on button on SideMenu
When a user click on a page button in the SideMenu, the drawer is closed and the navigation happens.
The HamburgerMenu component has an internal state that contains whether it should be an hamburger sign or an "X".
The problem is that the HamburgerMenu is not aware of this navigation (and thus not aware to the fact that the drawer was closed) so the icon is still "X" when the drawer is closed by the user's click.
I can't find a way to make the SideMenu notify HamburgerMenu about the change/event.
Here is the relevant code from App.js:
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen
},
Settings: {
screen: SettingsScreen
}
}, {
initialRouteName: 'Home',
contentComponent: SideMenu
});
const AppNavigator = createStackNavigator({
DrawerNavigator: {
screen: DrawerNavigator,
navigationOptions: ({ navigation }) => ({
headerLeft: <HamburgerMenu navigation={navigation} />
})
}
});
const AppContainer = createAppContainer(AppNavigator);
export default AppContainer;
EDIT:
Here is my HamburgerMenu code:
export default class HamburgerMenu extends Component {
constructor(props){
super(props);
this.state={
active: false
}
}
onPress(){
let newActive = !this.state.active;
this.setState({active: newActive});
if(newActive){
this.props.navigation.dispatch(DrawerActions.openDrawer())
}
else {
this.props.navigation.dispatch(DrawerActions.closeDrawer())
}
}
render(){
return (
<Hamburger active={this.state.active} type="spinCross" onPress={this.onPress.bind(this)} />
);
}
}
Thanks!
react-native react-navigation
add a comment |
When a user click on a page button in the SideMenu, the drawer is closed and the navigation happens.
The HamburgerMenu component has an internal state that contains whether it should be an hamburger sign or an "X".
The problem is that the HamburgerMenu is not aware of this navigation (and thus not aware to the fact that the drawer was closed) so the icon is still "X" when the drawer is closed by the user's click.
I can't find a way to make the SideMenu notify HamburgerMenu about the change/event.
Here is the relevant code from App.js:
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen
},
Settings: {
screen: SettingsScreen
}
}, {
initialRouteName: 'Home',
contentComponent: SideMenu
});
const AppNavigator = createStackNavigator({
DrawerNavigator: {
screen: DrawerNavigator,
navigationOptions: ({ navigation }) => ({
headerLeft: <HamburgerMenu navigation={navigation} />
})
}
});
const AppContainer = createAppContainer(AppNavigator);
export default AppContainer;
EDIT:
Here is my HamburgerMenu code:
export default class HamburgerMenu extends Component {
constructor(props){
super(props);
this.state={
active: false
}
}
onPress(){
let newActive = !this.state.active;
this.setState({active: newActive});
if(newActive){
this.props.navigation.dispatch(DrawerActions.openDrawer())
}
else {
this.props.navigation.dispatch(DrawerActions.closeDrawer())
}
}
render(){
return (
<Hamburger active={this.state.active} type="spinCross" onPress={this.onPress.bind(this)} />
);
}
}
Thanks!
react-native react-navigation
add a comment |
When a user click on a page button in the SideMenu, the drawer is closed and the navigation happens.
The HamburgerMenu component has an internal state that contains whether it should be an hamburger sign or an "X".
The problem is that the HamburgerMenu is not aware of this navigation (and thus not aware to the fact that the drawer was closed) so the icon is still "X" when the drawer is closed by the user's click.
I can't find a way to make the SideMenu notify HamburgerMenu about the change/event.
Here is the relevant code from App.js:
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen
},
Settings: {
screen: SettingsScreen
}
}, {
initialRouteName: 'Home',
contentComponent: SideMenu
});
const AppNavigator = createStackNavigator({
DrawerNavigator: {
screen: DrawerNavigator,
navigationOptions: ({ navigation }) => ({
headerLeft: <HamburgerMenu navigation={navigation} />
})
}
});
const AppContainer = createAppContainer(AppNavigator);
export default AppContainer;
EDIT:
Here is my HamburgerMenu code:
export default class HamburgerMenu extends Component {
constructor(props){
super(props);
this.state={
active: false
}
}
onPress(){
let newActive = !this.state.active;
this.setState({active: newActive});
if(newActive){
this.props.navigation.dispatch(DrawerActions.openDrawer())
}
else {
this.props.navigation.dispatch(DrawerActions.closeDrawer())
}
}
render(){
return (
<Hamburger active={this.state.active} type="spinCross" onPress={this.onPress.bind(this)} />
);
}
}
Thanks!
react-native react-navigation
When a user click on a page button in the SideMenu, the drawer is closed and the navigation happens.
The HamburgerMenu component has an internal state that contains whether it should be an hamburger sign or an "X".
The problem is that the HamburgerMenu is not aware of this navigation (and thus not aware to the fact that the drawer was closed) so the icon is still "X" when the drawer is closed by the user's click.
I can't find a way to make the SideMenu notify HamburgerMenu about the change/event.
Here is the relevant code from App.js:
const DrawerNavigator = createDrawerNavigator({
Home: {
screen: HomeScreen
},
Settings: {
screen: SettingsScreen
}
}, {
initialRouteName: 'Home',
contentComponent: SideMenu
});
const AppNavigator = createStackNavigator({
DrawerNavigator: {
screen: DrawerNavigator,
navigationOptions: ({ navigation }) => ({
headerLeft: <HamburgerMenu navigation={navigation} />
})
}
});
const AppContainer = createAppContainer(AppNavigator);
export default AppContainer;
EDIT:
Here is my HamburgerMenu code:
export default class HamburgerMenu extends Component {
constructor(props){
super(props);
this.state={
active: false
}
}
onPress(){
let newActive = !this.state.active;
this.setState({active: newActive});
if(newActive){
this.props.navigation.dispatch(DrawerActions.openDrawer())
}
else {
this.props.navigation.dispatch(DrawerActions.closeDrawer())
}
}
render(){
return (
<Hamburger active={this.state.active} type="spinCross" onPress={this.onPress.bind(this)} />
);
}
}
Thanks!
react-native react-navigation
react-native react-navigation
edited Jan 8 at 21:17
user3343396
asked Jan 1 at 19:32
user3343396user3343396
125
125
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
there is no event given for drawer as now but you can make your own by determining Whether drawer is open or close
const parent = this.props.navigation.dangerouslyGetParent();
const isDrawerOpen = parent && parent.state && parent.state.isDrawerOpen;
so you can maintain the state of the menu click inside the HamburgerMenu
or you can listen to the action from redux as well that is bit complex
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998336%2fforce-rerendering-hamburger-icon-when-clicking-on-button-on-sidemenu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
there is no event given for drawer as now but you can make your own by determining Whether drawer is open or close
const parent = this.props.navigation.dangerouslyGetParent();
const isDrawerOpen = parent && parent.state && parent.state.isDrawerOpen;
so you can maintain the state of the menu click inside the HamburgerMenu
or you can listen to the action from redux as well that is bit complex
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
add a comment |
there is no event given for drawer as now but you can make your own by determining Whether drawer is open or close
const parent = this.props.navigation.dangerouslyGetParent();
const isDrawerOpen = parent && parent.state && parent.state.isDrawerOpen;
so you can maintain the state of the menu click inside the HamburgerMenu
or you can listen to the action from redux as well that is bit complex
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
add a comment |
there is no event given for drawer as now but you can make your own by determining Whether drawer is open or close
const parent = this.props.navigation.dangerouslyGetParent();
const isDrawerOpen = parent && parent.state && parent.state.isDrawerOpen;
so you can maintain the state of the menu click inside the HamburgerMenu
or you can listen to the action from redux as well that is bit complex
there is no event given for drawer as now but you can make your own by determining Whether drawer is open or close
const parent = this.props.navigation.dangerouslyGetParent();
const isDrawerOpen = parent && parent.state && parent.state.isDrawerOpen;
so you can maintain the state of the menu click inside the HamburgerMenu
or you can listen to the action from redux as well that is bit complex
answered Jan 2 at 5:45
JigarJigar
726316
726316
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
add a comment |
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
This check will not help because the Hamburger component is not rendered. Where do you suggest i should put it? see Hamburger component code in my post edit
– user3343396
Jan 8 at 21:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998336%2fforce-rerendering-hamburger-icon-when-clicking-on-button-on-sidemenu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown