Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-rc9'
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed Jan 17, 2016
2 parents 47b51be + 7c8acd6 commit eed9892
Showing 12 changed files with 104 additions and 53 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<a name="1.0.0-rc9"></a>
### 1.0.0-rc9

* [BUG] stateGo API change <https://github.com/shprink/ionic-native-transitions/issues/35>
* [BUG] Hardware back does not close app <https://github.com/shprink/ionic-native-transitions/issues/47>
* [BUG] Pass `backCount` parameter to `$ionicNativeTransitions.goBack()` method <https://github.com/shprink/ionic-native-transitions/issues/53>

<a name="1.0.0-rc8"></a>
### 1.0.0-rc8

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ $ionicNativeTransitions.locationUrl('/yourUrl', {
## Using directives

```
<button native-ui-sref="tabs.home" native-ui-sref-opts="{reload: true}" native-options="{type: 'slide', direction:'down'}"></button>
<button native-ui-sref="tabs.home({param1: 'param1', param2: 'param2'})" native-ui-sref-opts="{reload: true}" native-options="{type: 'slide', direction:'down'}"></button>
```

## History back button
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ionic-native-transitions",
"version": "1.0.0-rc8",
"version": "1.0.0-rc9",
"description": "Native transitions for Ionic applications",
"main": [
"dist/ionic-native-transitions.js"
57 changes: 38 additions & 19 deletions dist/ionic-native-transitions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ionic-native-transitions.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ionic-native-transitions.min.js

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions lib/nativeSref.js
Original file line number Diff line number Diff line change
@@ -2,34 +2,43 @@ export default function($log, $ionicNativeTransitions, $state) {
'ngInject';

return {
link: link,
controller: controller,
restrict: 'A',
scope: false
};

function link(scope, element, attrs) {
function controller($scope, $element, $attrs, $state) {
'ngInject';

let state = attrs.nativeUiSref;
let optionsOverride = scope.$eval(attrs.nativeUiSrefOpts) || {};
let options = null;
let stateOptions = $scope.$eval($attrs.nativeUiSrefOpts) || {};
let nativeOptions = null;

attrs.$observe('nativeOptions', (newOptions) => {
let evalOptions = scope.$eval(newOptions);
options = angular.isObject(evalOptions) ? evalOptions : {};
$attrs.$observe('nativeOptions', (newOptions) => {
let evalOptions = $scope.$eval(newOptions);
nativeOptions = angular.isObject(evalOptions) ? evalOptions : {};
});

if (!state) {
return;
}

element.on('click', (event) => {
$element.on('click', (event) => {
let ref = parseStateRef($attrs.nativeUiSref, $state.current.name);
let params = angular.copy($scope.$eval(ref.paramExpr));
if (!$ionicNativeTransitions.isEnabled()) {
$state.go(state, optionsOverride);
$state.go(ref.state, params, stateOptions);
return;
}

$ionicNativeTransitions.stateGo(state, optionsOverride, options);
$ionicNativeTransitions.stateGo(ref.state, params, nativeOptions, stateOptions);
});
}
}

function parseStateRef(ref, current) {
var preparsed = ref.match(/^\s*({[^}]*})\s*$/),
parsed;
if (preparsed) ref = current + '(' + preparsed[1] + ')';
parsed = ref.replace(/\n/g, " ").match(/^([^(]+?)\s*(\((.*)\))?$/);
if (!parsed || parsed.length !== 4) throw new Error("Invalid state ref '" + ref + "'");
return {
state: parsed[1],
paramExpr: parsed[3] || null
};
}
31 changes: 20 additions & 11 deletions lib/provider.js
Original file line number Diff line number Diff line change
@@ -227,7 +227,7 @@ export default function() {
angular.extend(window.plugins.nativepagetransitions.globalOptions, getDefaultOptions());
}
$rootScope.$ionicGoBack = goBack;
backButtonUnregister = $ionicPlatform.registerBackButtonAction(goBack, 100);
backButtonUnregister = $ionicPlatform.registerBackButtonAction((e, count) => goBack(count), 100);
registerToRouteEvents();
} else {
$log.debug('[native transition] disabling plugin');
@@ -465,8 +465,16 @@ export default function() {
* @param {number} backCount - The number of views to go back to. default will be the previous view
*/
function goBack(backCount) {
if (!$ionicHistory.backView() || backCount >= 0) {
return;

if (!$ionicHistory.backView()) {
// Close the app when no more history
if (navigator.app) {
navigator.app.exitApp();
}
return;
}
if (backCount >= 0) {
return;
}
let stateName = $ionicHistory.backView().stateName;

@@ -475,21 +483,22 @@ export default function() {
// Get current history stack and find the cursor for the new view
// Based on the new cursor, find the new state to transition to
if (!!backCount && !isNaN(parseInt(backCount))) {
let viewHistory = $ionicHistory.viewHistory();
let currentHistory = viewHistory.histories[$ionicHistory.currentView().historyId];
let newCursor = currentHistory.cursor + backCount;
let viewHistory = $ionicHistory.viewHistory();
let currentHistory = viewHistory.histories[$ionicHistory.currentView().historyId];
let newCursor = currentHistory.cursor + backCount;

// If new cursor is more than the max possible or less than zero, default it to first view in history
if (newCursor < 0 || newCursor > currentHistory.stack.length) {
newCursor = 0;
}
// If new cursor is more than the max possible or less than zero, default it to first view in history
if (newCursor < 0 || newCursor > currentHistory.stack.length) {
newCursor = 0;
}

stateName = currentHistory.stack[newCursor].stateName;
stateName = currentHistory.stack[newCursor].stateName;
}

unregisterToStateChangeStartEvent();
let currentStateTransition = angular.extend({}, $state.current);
let toStateTransition = angular.extend({}, $state.get(stateName));
$log.debug('nativepagetransitions goBack', backCount, stateName, currentStateTransition, toStateTransition);
$ionicHistory.goBack(backCount);
transition('back', currentStateTransition, toStateTransition);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ionic-native-transitions",
"version": "1.0.0-rc8",
"version": "1.0.0-rc9",
"description": "Native transitions for Ionic applications",
"main": "dist/ionic-native-transitions.js",
"scripts": {
2 changes: 1 addition & 1 deletion test/config.js
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ export default function($ionicNativeTransitionsProvider, $stateProvider, $urlRou
templateUrl: "templates/three.html"
})
.state('four', {
url: "/four",
url: "/four?testParamUrl",
params: {
test: null
},
3 changes: 2 additions & 1 deletion test/controller.js
Original file line number Diff line number Diff line change
@@ -74,7 +74,8 @@ export default function(

function stateGo() {
$ionicNativeTransitions.stateGo('four', {
test: 'buyakacha!'
test: 'buyakacha!',
testParamUrl: 'hihi'
}, {
"type": "slide",
"direction": "up", // 'left|right|up|down', default 'left' (which is like 'next')
6 changes: 6 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -63,6 +63,12 @@
<a class="button button-full button-large icon icon-right ion-chevron-right" ng-click="main.disable()">Disable plugin</a>
<a class="button button-full button-large icon icon-right ion-chevron-right" ng-click="main.disableWithoutDisablingIonicTransitions()">Disable plugin and ionic transitions</a>
<a class="button button-full button-large icon icon-right ion-chevron-right" ng-click="main.stateGo()">StateGo</a>
<button class="button button-full button-large icon icon-right ion-chevron-right" native-ui-sref="four({test: 'buyakacha2!', testParamUrl: 'haha'})" native-ui-sref-opts="{inherit:false}" native-options="{type: 'slide', direction:'down'}">
StateGo via directive
</button>
<button class="button button-full button-large icon icon-right ion-chevron-right" native-ui-sref="four" native-ui-sref-opts="{inherit:false}">
StateGo via directive without native-options
</button>
<a class="button button-full button-large icon icon-right ion-chevron-right" ng-click="main.locationUrl()">LocationUrl</a>
</ion-content>
</ion-view>

0 comments on commit eed9892

Please sign in to comment.