Is there a way to render view content after the state transition is finished (I mean the animation)?
Some of our views are quite big and take a bit time to render. On some devices after touching the button we have around 2-3 second freeze before the transition starts. We managed to fix this issue using $timeout with 500ms delay but I don’t think it’s the best approach to do it…
ion-view
.content.loading-content(ng-if="!renderContent")
i.ion-loading-c
ion-content(ng-if="renderContent")
# all other stuff that will be rendered into DOM after 500ms
But it would be much better if we could just use some $scope.$on("$viewAnimationFinished") instead of just hardcoded 500ms, which might be too long for faster devices, like iOS 7.
Without this “fix”, we have huge delays (0.3s-1s) after clicking on any links on slower devices (Android, iOS6), which is caused by rendering the whole content’s view.
Before we will be able to somehow “prerender” the DOM into cache before the animation, I think this is the only way to make the application faster on those slower devices.
I am trying to achieve the same thing with some heavy views with multiple ng-repeats. Transitioning to the view before loading the content just makes the app seem so much more responsive to the user’s interactions - I really hope the Ionic devs will consider adding a better way to achieve this!
Right now, I’m playing around $stateChangeSuccess, which seems to work initially:
.controller('someCtrl', function($scope) {
$scope.$on('$stateChangeSuccess', function(){
*/ Load content from services and show ion-content */
}
})
Any thoughts on this solution?
EDIT: This only seems to work some of the time. It seems $stateChangeSuccess is not consistently fired after the transition, but may occasionally be fired before?
Have a look at the View LifeCycle and Events, it was added in beta.14 and is the solution to this problem. Specifically you will be interested in listening for the ‘$ionicView.afterEnter’ event.