Skip to content

Commit 5c8ca28

Browse files
[build] 1.3.8
1 parent 0796e72 commit 5c8ca28

File tree

12 files changed

+97
-41
lines changed

12 files changed

+97
-41
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 80
5+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ Apart from minor improvements and further testing of various mixes of Ionic comp
3939
| Router keep-alive | :heavy_check_mark: | [Pending](https://github.com/ionic-team/ionic/pull/18561) | - |
4040
| Functional Inputs | :heavy_check_mark: | [Pending](https://github.com/ionic-team/ionic/pull/19087) | - |
4141
| Import controllers directly | :heavy_check_mark: | [Pending](https://github.com/ionic-team/ionic/pull/19573) | Improve treeshaking and sync with react and angular implementations |
42+
| Restore scroll on navigation | :heavy_check_mark: | - | When going back through history restore the scroll position |
4243
| Unit tests | :x: | :x: | Outdated as were originally written in plain JS, need to be updated for TS |
4344

4445
## Ionic versions 4 and 5
4546
:warning: Moving forward all versions of `ionic-vue` will be supporting Ionic 5 only, if you'd like to continue using Ionic 4 please use `ionic-vue` version `1.3.4`
4647

4748
## Vue 3
48-
:construction: We are actively developing the next major version of this library. It will support Vue 3 and all of the new APIs like Composition, new transition features, etc.
49+
:construction: We are actively developing the next major version of this library. It will support Vue 3 and all of the new APIs like Composition, new transition features, etc.
4950

5051
## Installing / Getting started
5152

build/release.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ echo "Enter release version: "
55
read VERSION
66

77
read -p "Releasing $VERSION - are you sure? (y/n)" -n 1 -r
8-
echo # (optional) move to a new line
8+
echo # move to new line
9+
910
if [[ $REPLY =~ ^[Yy]$ ]]
1011
then
11-
npm run lint.fix
1212
echo "Releasing $VERSION ..."
1313
VERSION=$VERSION npm run prod
1414

1515
# commit
16+
npm version $VERSION --no-git-tag-version
1617
git add -A
17-
git commit --allow-empty -m "[build] $VERSION"
18-
npm version $VERSION --message "[release] $VERSION"
18+
git commit -m "[build] $VERSION"
19+
git tag v$VERSION
1920

2021
# publish
21-
git push origin refs/tags/v$VERSION
22-
git push
22+
git push --tags
2323
npm publish
2424
fi

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modus/ionic-vue",
3-
"version": "1.3.7",
3+
"version": "1.3.8",
44
"description": "Ionic integration adapters for Vue",
55
"homepage": "https://moduscreate.com",
66
"author": "Michael Tintiuc <michael.tintiuc@moduscreate.com>",
@@ -49,9 +49,8 @@
4949
"scripts": {
5050
"dev": "rollup -c ./build/rollup.config.js",
5151
"watch": "rollup -w -c ./build/rollup.config.js",
52-
"prod": "npm run clean && NODE_ENV=production rollup -c ./build/rollup.config.js --configProd",
53-
"lint": "tslint --project .",
54-
"lint.fix": "tslint --project . --fix",
52+
"prod": "npm run lint && npm run clean && NODE_ENV=production rollup -c ./build/rollup.config.js --configProd",
53+
"lint": "tslint --project . --fix",
5554
"test": "jest --coverage --verbose",
5655
"install.peer": "npm i --no-save vue vue-template-compiler vue-router @ionic/core",
5756
"clean": "node ./scripts/clean.js"

src/components/ion-vue-router.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ export default {
5050
leave: (el: HTMLElement, done: TransitionDone) => {
5151
leave(parent, props as Props, el, done);
5252
},
53+
enter: (el: HTMLElement, done: TransitionDone) => {
54+
enter(parent, el, done);
55+
},
5356
beforeEnter,
54-
enter,
5557
afterEnter,
5658
beforeLeave,
5759
afterLeave,
@@ -107,28 +109,19 @@ function catchIonicGoBack(parent: Vue, event: Event): void {
107109
}
108110

109111
// Transition when we leave the route
110-
function leave(
112+
async function leave(
111113
parent: Vue,
112114
props: Props,
113115
el: HTMLElement,
114116
done: TransitionDone
115117
) {
116-
const promise = transition(parent, props, el);
117-
118-
// Skip any transition if we don't get back a Promise
119-
if (!promise) {
120-
done();
121-
return;
122-
}
118+
await parent.$router.saveScroll(el);
123119

124120
// Perform navigation once the transition was finished
125-
parent.$router.transition = new Promise(resolve => {
126-
promise
127-
.then(() => {
128-
resolve();
129-
done();
130-
})
131-
.catch(console.error);
121+
parent.$router.transition = new Promise(async resolve => {
122+
await transition(parent, props, el);
123+
done();
124+
resolve();
132125
});
133126
}
134127

@@ -180,8 +173,14 @@ function beforeEnter(el: HTMLElement) {
180173
}
181174

182175
// Enter the new route
183-
function enter(_el: HTMLElement, done: TransitionDone) {
184-
done();
176+
function enter(parent: Vue, el: HTMLElement, done: TransitionDone) {
177+
if (parent.$router.direction === 'back') {
178+
parent.$router
179+
.restoreScroll(el, parent.$router.currentRoute.fullPath)
180+
.then(done);
181+
} else {
182+
done();
183+
}
185184
}
186185

187186
// Vue transition stub functions

src/interfaces.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ declare module 'vue-router/types/router' {
88
direction: RouterDirection;
99
directionOverride: RouterDirection | null;
1010
transition: Promise<void>;
11+
saveScroll(el: HTMLElement): Promise<void>;
12+
restoreScroll(el: HTMLElement, key: string): Promise<void>;
1113
canGoBack(): boolean;
1214
}
1315
}
@@ -42,16 +44,28 @@ export interface IonicWindow extends Window {
4244
}
4345

4446
export interface FrameworkDelegate {
45-
attachViewToDom(parentElement: HTMLElement, component: HTMLElement | WebpackFunction | object | Vue, opts?: object, classes?: string[]): Promise<HTMLElement>;
46-
removeViewFromDom(parentElement: HTMLElement, childElement: HTMLVueElement): Promise<void>;
47+
attachViewToDom(
48+
parentElement: HTMLElement,
49+
component: HTMLElement | WebpackFunction | object | Vue,
50+
opts?: object,
51+
classes?: string[]
52+
): Promise<HTMLElement>;
53+
removeViewFromDom(
54+
parentElement: HTMLElement,
55+
childElement: HTMLVueElement
56+
): Promise<void>;
4757
}
4858

4959
export interface IonBackButton extends HTMLStencilElement {
5060
defaultHref?: string;
5161
}
5262

5363
export interface IonRouterOutlet extends HTMLStencilElement {
54-
commit(enterinEl: HTMLElement, leavingEl: HTMLElement | undefined, opts?: object | undefined): Promise<boolean>;
64+
commit(
65+
enterinEl: HTMLElement,
66+
leavingEl: HTMLElement | undefined,
67+
opts?: object | undefined
68+
): Promise<boolean>;
5569
}
5670

5771
export interface ApiCache {

src/router.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ export default class Router extends VueRouter {
1010
directionOverride: RouterDirection | null;
1111
viewCount: number;
1212
prevRouteStack: Route[];
13+
cachedPrevRoute: Route;
1314
history: any;
15+
scroll: Map<string, { top: number; left: number }>;
1416
static installed: boolean;
1517
static install: PluginFunction<never>;
1618

1719
constructor(args: RouterArgs = {} as RouterArgs) {
1820
super(args);
1921

22+
// Set default scroll stack
23+
this.scroll = new Map();
24+
2025
// The direction user navigates in
2126
this.direction = args.direction || 'forward';
2227

@@ -41,6 +46,10 @@ export default class Router extends VueRouter {
4146
});
4247
}
4348

49+
get prevRoute(): Route | undefined {
50+
return this.prevRouteStack[this.prevRouteStack.length - 1];
51+
}
52+
4453
extendTransitionConfirmation() {
4554
this.history._confirmTransition = this.history.confirmTransition;
4655
this.history.confirmTransition = async (...opts: any) => {
@@ -82,13 +91,13 @@ export default class Router extends VueRouter {
8291
}
8392

8493
guessDirection(nextRoute: Route): RouterDirection {
85-
if (this.prevRouteStack.length !== 0) {
86-
const prevRoute: Route = this.prevRouteStack[this.prevRouteStack.length - 1];
94+
this.cachedPrevRoute = this.history.current;
8795

96+
if (this.prevRoute) {
8897
// Last route is the same as the next one - go back
8998
// If we're going to / reset the stack otherwise pop a route
90-
if (prevRoute.fullPath === nextRoute.fullPath) {
91-
if (prevRoute.fullPath.length === 1) {
99+
if (this.prevRoute.fullPath === nextRoute.fullPath) {
100+
if (this.prevRoute.fullPath.length === 1) {
92101
this.prevRouteStack = [];
93102
} else {
94103
this.prevRouteStack.pop();
@@ -101,8 +110,27 @@ export default class Router extends VueRouter {
101110
if (this.history.current.fullPath !== nextRoute.fullPath) {
102111
this.prevRouteStack.push(this.history.current);
103112
}
113+
104114
return 'forward';
105115
}
116+
117+
async saveScroll(el: HTMLElement): Promise<void> {
118+
const ionContent = el.querySelector('ion-content');
119+
const scrollElement = ionContent && (await ionContent.getScrollElement());
120+
121+
if (scrollElement) {
122+
this.scroll.set(this.cachedPrevRoute.fullPath, {
123+
top: scrollElement?.scrollTop || 0,
124+
left: scrollElement?.scrollLeft || 0,
125+
});
126+
}
127+
}
128+
129+
async restoreScroll(el: HTMLElement, key: string): Promise<void> {
130+
const ionContent = el.querySelector('ion-content');
131+
const scrollElement = ionContent && (await ionContent.getScrollElement());
132+
scrollElement?.scrollTo(this.scroll.get(key) || { top: 0, left: 0 });
133+
}
106134
}
107135

108136
Router.install = (Vue) => {

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./createOverlayComponent";
2-
export * from "./createInputComponent";
1+
export * from './createOverlayComponent';
2+
export * from './createInputComponent';

types/interfaces.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ declare module 'vue-router/types/router' {
77
direction: RouterDirection;
88
directionOverride: RouterDirection | null;
99
transition: Promise<void>;
10+
saveScroll(el: HTMLElement): Promise<void>;
11+
restoreScroll(el: HTMLElement, key: string): Promise<void>;
1012
canGoBack(): boolean;
1113
}
1214
}

0 commit comments

Comments
 (0)