Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Back button issue #122

Closed
jgw96 opened this issue Jan 13, 2017 · 27 comments
Closed

Back button issue #122

jgw96 opened this issue Jan 13, 2017 · 27 comments
Labels

Comments

@jgw96
Copy link
Contributor

jgw96 commented Jan 13, 2017

From @kraskoshnyy on June 13, 2016 8:5

Short description of the problem:

Back button becomes hidden, looks like some problems with ionicHistory

What behavior are you expecting?

Click on the button should change state to previous

Steps to reproduce:

  1. You need at least two tabs. where you have "sub pages"
  2. Click on first tab, then subpage and click back
  3. Do the same with second tab
  4. Go to first tab
  5. The same with second tab
  6. Repeat navTransition doesn't play nicely with ngIf #2
  7. No back button on sub page on tab 2 & 1

Attached images

Which Ionic Version? 1.x or 2.x
1.3.1
screen shot 2016-06-13 at 1 02 15 am
screen shot 2016-06-13 at 1 02 25 am
screen shot 2016-06-13 at 1 02 37 am

Copied from original issue: ionic-team/ionic-framework#6875

@jgw96 jgw96 added the v1 label Jan 13, 2017
@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @kraskoshnyy on June 14, 2016 5:9

So confirmed, the problem with backView:
This code answer viewHistory before actions:

Object
backView: View {viewId: "ion9", index: 0, historyId: "ion5", backViewId: "ion7", forwardViewId: "ion10", …}
currentView: View {viewId: "ion10", index: 1, historyId: "ion5", backViewId: "ion9", forwardViewId: null, …}
forwardView: null
histories: {root: Object, ion3: Object, ion4: Object, ion5: Object}
views: {ion2: View, ion6: View, ion7: View, ion8: View, ion9: View, …}

After:

backView: null
currentView: View {viewId: "ion10", index: 1, historyId: "ion5", backViewId: null, forwardViewId: null, …}
forwardView: null
histories: {root: Object, ion3: Object, ion4: Object, ion5: Object}
views: {ion2: View, ion6: View, ion7: View, ion8: View, ion9: View, …}

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @chmln on June 16, 2016 19:13

+1

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @LightZam on June 17, 2016 6:46

+1

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @LightZam on July 15, 2016 1:12

any solution?
or anyone has workaround solution?
or anyone can confirm which version work fine

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @kraskoshnyy on July 15, 2016 2:14

I fixed this way, I keep history in $rootScope.appScope.viewBack

$scope.$on("$ionicView.beforeEnter", function(event, viewData){
viewData.enableBack = true;
if($ionicHistory.backView() != null) {
$rootScope.appScope.viewBack[$state.current.name] = $ionicHistory.backView();
}
else if(typeof $rootScope.appScope.viewBack[$state.current.name] != undefined) {
$ionicHistory.viewHistory().backView = $rootScope.appScope.viewBack[$state.current.name];
}
});

Works perfectly for me

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @LightZam on July 15, 2016 5:52

@kraskoshnyy thanks, i will try it

and more , i had confirm the version.

ionic lib 1.3.0 works fine, the bug comes out with 1.3.1

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @gzfgeh on August 24, 2016 6:5

what is this "appScope"? Cannot read property 'viewBack' of undefined

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @Focushift on August 28, 2016 8:50

Have same problem with Back button when navigating between 3 views. If I check $ionicHistory.viewHistory().currentView when coming from 3 to 2 view, backView becomes null.
Here my ugly code that helps to solve problem and later adds another:
$rootScope.$on('$stateChangeSuccess', function () {
if ($ionicHistory.viewHistory().currentView.stateId == 'garage' || $ionicHistory.viewHistory().currentView.stateId == 'login') {
var s = {};
s.back = $ionicHistory.viewHistory().currentView;
s.view = $ionicHistory.viewHistory().views[s.back.viewId];
StoreService.storeData('apphistory', s);
}
if ($ionicHistory.viewHistory().histories.ion1.cursor > 0) {
setTimeout(function () {
console.log(angular.copy($ionicHistory.viewHistory()));
if ($ionicHistory.viewHistory().currentView.index == 0) {
try {
angular.element(document.querySelectorAll("[nav-bar]")[0].childNodes[0].childNodes[0]).addClass('hide');
angular.element(document.querySelectorAll("[nav-bar]")[0].childNodes[1].childNodes[0]).addClass('hide');
} catch (e) { }
}
if ($ionicHistory.viewHistory().backView == null && $ionicHistory.viewHistory().histories.ion1.cursor > 1) {
console.log('alert');
var s = angular.copy(StoreService.getData('apphistory'));
$ionicHistory.viewHistory().backView = s.back;
$ionicHistory.viewHistory().views[s.back.viewId] = s.view;
$ionicHistory.viewHistory().currentView.backViewId = s.back.viewId;
$ionicHistory.viewHistory().views[$ionicHistory.viewHistory().currentView.viewId].backViewId = s.back.viewId;
var ar = angular.copy($ionicHistory.viewHistory().histories.ion1.stack);
$ionicHistory.viewHistory().histories.ion1.stack = [];
$ionicHistory.viewHistory().histories.ion1.stack.push(s.back);
$ionicHistory.viewHistory().histories.ion1.stack.push(ar[0]);
$ionicHistory.viewHistory().histories.ion1.cursor--;
console.log($ionicHistory.viewHistory());
angular.element(document.querySelectorAll("[nav-bar='active']")[0].childNodes[0].childNodes[0]).removeClass('hide');
}
}, 300);
} else setTimeout(function () { console.log(angular.copy($ionicHistory.viewHistory())); }, 300);
});

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @DrJonnie on September 1, 2016 7:9

Hi,

in my opinion this bug is really a show stopper. And the ionic team should investigate ASAP.

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @loopezz on September 15, 2016 11:15

+1

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @oguzserdar on September 28, 2016 21:8

+1

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @jpost on September 29, 2016 14:32

+1, and I can confirm the bug does not appear in 1.3.0, at least for me.

I think I found the bug in the code. This block was added around line 54054 in ionic.bundle.js. It appears to have been added to fix some other bug, but introduced this bug.

// the new view is being removed from it's old position in the history and being placed at the top,
// so we need to update any views that reference it as a backview, otherwise there will be infinitely loops
var viewIds = Object.keys(viewHistory.views);
    viewIds.forEach(function(viewId) {
    var view = viewHistory.views[viewId];
    if ( view.backViewId === switchToView.viewId ) {
      view.backViewId = null;
    }
});

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @Focushift on September 30, 2016 14:22

Commented that block, not helps.

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @DrJonnie on November 7, 2016 11:52

Hi, does anybody know whether there is some progress on this bug?
Ionic 1.3.2 is out, can anybody confirm wheteher this bug still exists?

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @AlDrag on November 25, 2016 4:13

Has this still not been fixed? I am still having massive issues with this. Is it fixed in V2 at least?

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @oguzserdar on November 25, 2016 9:55

It's not a problem in V2.

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @DrJonnie on November 29, 2016 8:32

Personally, I'm a little bit disappointed. I understand that the Ionic dev team is primarily focused
on the v2 release, but v2 is still not ready for production use. Therefore I can not understand
that this primary navigation BUG ist still not resolved and that since two v1 releases!

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @AlDrag on December 4, 2016 22:38

I agree DrJonnie. But maybe we can try contribute to helping the problem through a pull request? :) Just need to find the cause of the bug.

@jgw96
Copy link
Contributor Author

jgw96 commented Jan 13, 2017

From @gabrielbazan7 on December 22, 2016 20:50

Just send a PR to Bitpay/Copay Wallet ionic project solving this issue. Feel free to take a look: https://github.com/bitpay/copay/pull/5333
And tell me if it works on your proyect, please.

Here is the code.

$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
 if (!$rootScope.viewBack) $rootScope.viewBack = {};
 if ($ionicHistory.viewHistory() && $ionicHistory.viewHistory().backView != null)
   $rootScope.viewBack[fromState.name] = $ionicHistory.viewHistory().backView;
});

Then, in each view (I do it once because I have a TabController that contains all tabs views - although viewData.enableBack = true needs to be done in each controller, I cannot get this solved):

$scope.$on("$ionicView.beforeEnter", function(event, viewData) {
  if ($ionicHistory.viewHistory() && !$ionicHistory.viewHistory().backView) {
    $ionicHistory.viewHistory().backView = $rootScope.viewBack[data.stateName];
    viewData.enableBack = true;
 }
});

@mastronaute
Copy link

Hi, I am totally confused about different workarounds... so far, what would be the best workaround to "force" display of back button in sub views that loses view history ?
Can't go to production because of this...

@SwenVogel
Copy link

+1

@mastronaute
Copy link

Don't get me wrong here, you have been doing some amazing work with Ionic but this is serious show stopper. I cannot consider for one sec releasing with this issue so please advise on how we can workaround.
Beside, at some point in my sub-view I am hiding the tabs so once the error occurs and the back button disappears the user is stuck and the app becomes unusable...

@w3development-kn
Copy link

+1

@w3development-kn
Copy link

w3development-kn commented Jan 30, 2017

I have tested this issue with 1.3.0. It is not present there. So downgrade to 1.3.0 sucks but is the only working solution right now... at least for me

@mastronaute
Copy link

I tried @gabrielbazan7 solution which works well on my side.

@skounis
Copy link

skounis commented Feb 13, 2017

+1

mlynch added a commit that referenced this issue Feb 22, 2017
fix(history): fixes Back Button issue (#122). Issue occurs when switc…
@mlynch
Copy link
Contributor

mlynch commented Feb 22, 2017

Just merged #210 which fixes this issue for a lot of people. Please try the latest version in master

@mlynch mlynch closed this as completed Feb 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants