├── .firebaserc ├── .gitignore ├── LICENSE ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── firebase.json ├── ionic.config.json ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── blocking-resolver │ │ ├── blocking-resolver.module.ts │ │ ├── blocking-resolver.page.html │ │ ├── blocking-resolver.page.scss │ │ ├── blocking-resolver.page.ts │ │ └── blocking.resolver.ts │ ├── components │ │ ├── components.module.ts │ │ ├── image-shell │ │ │ ├── image-shell.component.html │ │ │ ├── image-shell.component.scss │ │ │ └── image-shell.component.ts │ │ └── text-shell │ │ │ ├── text-shell.component.html │ │ │ ├── text-shell.component.scss │ │ │ └── text-shell.component.ts │ ├── home │ │ ├── home.module.ts │ │ ├── home.page.html │ │ ├── home.page.scss │ │ └── home.page.ts │ ├── non-blocking-resolver │ │ ├── non-blocking-resolver.module.ts │ │ ├── non-blocking-resolver.page.html │ │ ├── non-blocking-resolver.page.scss │ │ ├── non-blocking-resolver.page.ts │ │ └── non-blocking.resolver.ts │ └── progressive-shell-resolver │ │ ├── progressive-shell-resolver.module.ts │ │ ├── progressive-shell-resolver.page.html │ │ ├── progressive-shell-resolver.page.scss │ │ ├── progressive-shell-resolver.page.ts │ │ ├── progressive-shell.resolver.ts │ │ ├── sample-shell.model.ts │ │ ├── shell-elements.scss │ │ └── shell.provider.ts ├── assets │ ├── icon │ │ └── favicon.png │ ├── sample-data │ │ └── page-data.json │ └── shapes.svg ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── global.scss ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── test.ts ├── theme │ └── variables.scss ├── tsconfig.app.json └── tsconfig.spec.json ├── tsconfig.json └── tslint.json /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "ionic-4-app-shell" 4 | } 5 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Specifies intentionally untracked files to ignore when using Git 2 | # http://git-scm.com/docs/gitignore 3 | 4 | *~ 5 | *.sw[mnpcod] 6 | *.log 7 | *.tmp 8 | *.tmp.* 9 | log.txt 10 | *.sublime-project 11 | *.sublime-workspace 12 | .vscode/ 13 | npm-debug.log* 14 | 15 | .idea/ 16 | .ionic/ 17 | .sourcemaps/ 18 | .sass-cache/ 19 | .tmp/ 20 | .versions/ 21 | coverage/ 22 | www/ 23 | node_modules/ 24 | tmp/ 25 | temp/ 26 | platforms/ 27 | plugins/ 28 | plugins/android.json 29 | plugins/ios.json 30 | $RECYCLE.BIN/ 31 | 32 | .DS_Store 33 | Thumbs.db 34 | UserInterfaceState.xcuserstate 35 | 36 | .firebase/ 37 | post-assets/ 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Agustin Haller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Improved UX for Ionic apps with Skeleton Loading Screens 2 | 3 | ### Ionic Free Starter App 4 | UI Skeletons, Ghost Elements, Shell Elements? They are all the same! Think of them as cool content placeholders that are shown where the content will eventually be once it becomes available. 5 | 6 | This repo is part of [Ionic Skeleton Components Tutorial](https://ionicthemes.com/tutorials/about/improved-ux-for-ionic-apps-with-skeleton-loading-screens) where you will learn the importance of adopting the App Shell pattern in your ionic apps. Also, you will learn how to add Skeleton components to your Ionic Angular apps. 7 | 8 | ### Start with Ionic Framework 9 | This post is part of the *Mastering Ionic Framework* series which deep dives into Ionic more advanced stuff. If you are new to Ionic Framwork, I strongly recommend you to first read our [previous introductory ionic 5 tutorial](https://ionicthemes.com/tutorials/about/ionic5-tutorial-migration-and-starter) 10 | 11 | ### Install this Ionic free starter app 12 | ``` 13 | npm install 14 | ``` 15 | 16 | ### Browse the Ionic App 17 | ``` 18 | ionic serve 19 | ``` 20 | 21 | ### Demo 22 | [Try this app](https://ionic-4-app-shell.firebaseapp.com/home). 23 | 24 | ### Free Ionic Examples 25 | Find more Ionic 5 tutorials and freebies in [IonicThemes](https://ionicthemes.com/tutorials). 26 | 27 | ### Get a premium Ionic 5 Starter App 28 | The following skeleton animations are part of our latest [Ionic 5 Full Starter App](https://ionicthemes.com/product/ionic5-full-starter-app). It's an ionic template that you can use to jump start your app development and save yourself hundreds of hours of design and development. 29 | 30 | It also has lots of practical use cases you can use to learn Ionic Framework! 31 | 32 | 33 |

34 | 35 | 36 | 37 |

38 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json", 3 | "version": 1, 4 | "defaultProject": "app", 5 | "newProjectRoot": "projects", 6 | "projects": { 7 | "app": { 8 | "root": "", 9 | "sourceRoot": "src", 10 | "projectType": "application", 11 | "prefix": "app", 12 | "schematics": {}, 13 | "architect": { 14 | "build": { 15 | "builder": "@angular-devkit/build-angular:browser", 16 | "options": { 17 | "outputPath": "www", 18 | "index": "src/index.html", 19 | "main": "src/main.ts", 20 | "polyfills": "src/polyfills.ts", 21 | "tsConfig": "src/tsconfig.app.json", 22 | "assets": [ 23 | { 24 | "glob": "**/*", 25 | "input": "src/assets", 26 | "output": "assets" 27 | }, 28 | { 29 | "glob": "**/*.svg", 30 | "input": "node_modules/ionicons/dist/ionicons/svg", 31 | "output": "./svg" 32 | } 33 | ], 34 | "styles": [ 35 | { 36 | "input": "src/theme/variables.scss" 37 | }, 38 | { 39 | "input": "src/global.scss" 40 | } 41 | ], 42 | "scripts": [], 43 | "es5BrowserSupport": true 44 | }, 45 | "configurations": { 46 | "production": { 47 | "fileReplacements": [ 48 | { 49 | "replace": "src/environments/environment.ts", 50 | "with": "src/environments/environment.prod.ts" 51 | } 52 | ], 53 | "optimization": true, 54 | "outputHashing": "all", 55 | "sourceMap": false, 56 | "extractCss": true, 57 | "namedChunks": false, 58 | "aot": true, 59 | "extractLicenses": true, 60 | "vendorChunk": false, 61 | "buildOptimizer": true, 62 | "budgets": [ 63 | { 64 | "type": "initial", 65 | "maximumWarning": "2mb", 66 | "maximumError": "5mb" 67 | } 68 | ] 69 | }, 70 | "ci": { 71 | "progress": false 72 | } 73 | } 74 | }, 75 | "serve": { 76 | "builder": "@angular-devkit/build-angular:dev-server", 77 | "options": { 78 | "browserTarget": "app:build" 79 | }, 80 | "configurations": { 81 | "production": { 82 | "browserTarget": "app:build:production" 83 | }, 84 | "ci": { 85 | "progress": false 86 | } 87 | } 88 | }, 89 | "extract-i18n": { 90 | "builder": "@angular-devkit/build-angular:extract-i18n", 91 | "options": { 92 | "browserTarget": "app:build" 93 | } 94 | }, 95 | "test": { 96 | "builder": "@angular-devkit/build-angular:karma", 97 | "options": { 98 | "main": "src/test.ts", 99 | "polyfills": "src/polyfills.ts", 100 | "tsConfig": "src/tsconfig.spec.json", 101 | "karmaConfig": "src/karma.conf.js", 102 | "styles": [], 103 | "scripts": [], 104 | "assets": [ 105 | { 106 | "glob": "favicon.ico", 107 | "input": "src/", 108 | "output": "/" 109 | }, 110 | { 111 | "glob": "**/*", 112 | "input": "src/assets", 113 | "output": "/assets" 114 | } 115 | ] 116 | }, 117 | "configurations": { 118 | "ci": { 119 | "progress": false, 120 | "watch": false 121 | } 122 | } 123 | }, 124 | "lint": { 125 | "builder": "@angular-devkit/build-angular:tslint", 126 | "options": { 127 | "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"], 128 | "exclude": ["**/node_modules/**"] 129 | } 130 | }, 131 | "ionic-cordova-build": { 132 | "builder": "@ionic/angular-toolkit:cordova-build", 133 | "options": { 134 | "browserTarget": "app:build" 135 | }, 136 | "configurations": { 137 | "production": { 138 | "browserTarget": "app:build:production" 139 | } 140 | } 141 | }, 142 | "ionic-cordova-serve": { 143 | "builder": "@ionic/angular-toolkit:cordova-serve", 144 | "options": { 145 | "cordovaBuildTarget": "app:ionic-cordova-build", 146 | "devServerTarget": "app:serve" 147 | }, 148 | "configurations": { 149 | "production": { 150 | "cordovaBuildTarget": "app:ionic-cordova-build:production", 151 | "devServerTarget": "app:serve:production" 152 | } 153 | } 154 | } 155 | } 156 | }, 157 | "app-e2e": { 158 | "root": "e2e/", 159 | "projectType": "application", 160 | "architect": { 161 | "e2e": { 162 | "builder": "@angular-devkit/build-angular:protractor", 163 | "options": { 164 | "protractorConfig": "e2e/protractor.conf.js", 165 | "devServerTarget": "app:serve" 166 | }, 167 | "configurations": { 168 | "ci": { 169 | "devServerTarget": "app:serve:ci" 170 | } 171 | } 172 | }, 173 | "lint": { 174 | "builder": "@angular-devkit/build-angular:tslint", 175 | "options": { 176 | "tsConfig": "e2e/tsconfig.e2e.json", 177 | "exclude": ["**/node_modules/**"] 178 | } 179 | } 180 | } 181 | } 182 | }, 183 | "cli": { 184 | "defaultCollection": "@ionic/angular-toolkit" 185 | }, 186 | "schematics": { 187 | "@ionic/angular-toolkit:component": { 188 | "styleext": "scss" 189 | }, 190 | "@ionic/angular-toolkit:page": { 191 | "styleext": "scss" 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('new App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | describe('default screen', () => { 10 | beforeEach(() => { 11 | page.navigateTo('/home'); 12 | }); 13 | it('should have a title saying Home', () => { 14 | page.getPageOneTitleText().then(title => { 15 | expect(title).toEqual('Home'); 16 | }); 17 | }); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(destination) { 5 | return browser.get(destination); 6 | } 7 | 8 | getTitle() { 9 | return browser.getTitle(); 10 | } 11 | 12 | getPageOneTitleText() { 13 | return element(by.tagName('app-home')).element(by.deepCss('ion-title')).getText(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "www", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ], 9 | "rewrites": [ 10 | { 11 | "source": "**", 12 | "destination": "/index.html" 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ionic.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-4-app-shell-components", 3 | "integrations": {}, 4 | "type": "angular" 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ionic-4-app-shell-components", 3 | "version": "0.0.1", 4 | "author": "Ionic Framework", 5 | "homepage": "https://ionicframework.com/", 6 | "scripts": { 7 | "ng": "ng", 8 | "start": "ng serve", 9 | "build": "ng build", 10 | "test": "ng test", 11 | "lint": "ng lint", 12 | "e2e": "ng e2e" 13 | }, 14 | "private": true, 15 | "dependencies": { 16 | "@angular/common": "^7.2.2", 17 | "@angular/core": "^7.2.2", 18 | "@angular/forms": "^7.2.2", 19 | "@angular/http": "^7.2.2", 20 | "@angular/platform-browser": "^7.2.2", 21 | "@angular/platform-browser-dynamic": "^7.2.2", 22 | "@angular/router": "^7.2.2", 23 | "@ionic-native/core": "^5.0.0", 24 | "@ionic-native/splash-screen": "^5.0.0", 25 | "@ionic-native/status-bar": "^5.0.0", 26 | "@ionic/angular": "^4.1.0", 27 | "core-js": "^2.5.4", 28 | "rxjs": "~6.3.3", 29 | "zone.js": "~0.8.29" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/architect": "~0.12.3", 33 | "@angular-devkit/build-angular": "~0.13.0", 34 | "@angular-devkit/core": "~7.2.3", 35 | "@angular-devkit/schematics": "~7.2.3", 36 | "@angular/cli": "~7.3.1", 37 | "@angular/compiler": "~7.2.2", 38 | "@angular/compiler-cli": "~7.2.2", 39 | "@angular/language-service": "~7.2.2", 40 | "@ionic/angular-toolkit": "~1.4.0", 41 | "@types/node": "~10.12.0", 42 | "@types/jasmine": "~2.8.8", 43 | "@types/jasminewd2": "~2.0.3", 44 | "codelyzer": "~4.5.0", 45 | "jasmine-core": "~2.99.1", 46 | "jasmine-spec-reporter": "~4.2.1", 47 | "karma": "~3.1.4", 48 | "karma-chrome-launcher": "~2.2.0", 49 | "karma-coverage-istanbul-reporter": "~2.0.1", 50 | "karma-jasmine": "~1.1.2", 51 | "karma-jasmine-html-reporter": "^0.2.2", 52 | "protractor": "~5.4.0", 53 | "ts-node": "~8.0.0", 54 | "tslint": "~5.12.0", 55 | "typescript": "~3.1.6" 56 | }, 57 | "description": "An Ionic project" 58 | } 59 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | const routes: Routes = [ 5 | { 6 | path: '', 7 | redirectTo: 'home', 8 | pathMatch: 'full' 9 | }, 10 | { 11 | path: 'home', 12 | loadChildren: './home/home.module#HomePageModule' 13 | }, 14 | // Resolvers 15 | { 16 | path: 'blocking-resolver', 17 | loadChildren: './blocking-resolver/blocking-resolver.module#BlockingResolverPageModule' 18 | }, 19 | { 20 | path: 'non-blocking-resolver', 21 | loadChildren: './non-blocking-resolver/non-blocking-resolver.module#NonBlockingResolverPageModule' 22 | }, 23 | { 24 | path: 'progressive-shell-resolver', 25 | loadChildren: './progressive-shell-resolver/progressive-shell-resolver.module#ProgressiveShellResolverPageModule' 26 | } 27 | ]; 28 | 29 | @NgModule({ 30 | imports: [RouterModule.forRoot(routes)], 31 | exports: [RouterModule] 32 | }) 33 | export class AppRoutingModule {} 34 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Menu 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | {{p.title}} 15 | 16 | 17 | 18 | 19 | 20 | Route Resolves 21 | 22 | 23 | 24 | {{p.title}} 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | import { Platform } from '@ionic/angular'; 4 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 5 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 6 | 7 | @Component({ 8 | selector: 'app-root', 9 | templateUrl: 'app.component.html' 10 | }) 11 | export class AppComponent { 12 | public appPages = [ 13 | { 14 | title: 'Home', 15 | url: '/home' 16 | } 17 | ]; 18 | 19 | public routeResolversPages = [ 20 | { 21 | title: 'Blocking Resolver', 22 | url: '/blocking-resolver' 23 | }, 24 | { 25 | title: 'Non Blocking Resolver', 26 | url: '/non-blocking-resolver' 27 | }, 28 | { 29 | title: 'Progressive Shell Resolver', 30 | url: '/progressive-shell-resolver' 31 | } 32 | ]; 33 | 34 | constructor( 35 | private platform: Platform, 36 | private splashScreen: SplashScreen, 37 | private statusBar: StatusBar 38 | ) { 39 | this.initializeApp(); 40 | } 41 | 42 | initializeApp() { 43 | this.platform.ready().then(() => { 44 | this.statusBar.styleDefault(); 45 | this.splashScreen.hide(); 46 | }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { RouteReuseStrategy } from '@angular/router'; 4 | 5 | import { IonicModule, IonicRouteStrategy } from '@ionic/angular'; 6 | import { SplashScreen } from '@ionic-native/splash-screen/ngx'; 7 | import { StatusBar } from '@ionic-native/status-bar/ngx'; 8 | 9 | import { AppComponent } from './app.component'; 10 | import { AppRoutingModule } from './app-routing.module'; 11 | 12 | @NgModule({ 13 | declarations: [AppComponent], 14 | entryComponents: [], 15 | imports: [ 16 | BrowserModule, 17 | IonicModule.forRoot(), 18 | AppRoutingModule 19 | ], 20 | providers: [ 21 | StatusBar, 22 | SplashScreen, 23 | { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } 24 | ], 25 | bootstrap: [AppComponent] 26 | }) 27 | export class AppModule {} 28 | -------------------------------------------------------------------------------- /src/app/blocking-resolver/blocking-resolver.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | 7 | import { IonicModule } from '@ionic/angular'; 8 | 9 | import { BlockingResolverPage } from './blocking-resolver.page'; 10 | import { BlockingResolver } from './blocking.resolver'; 11 | 12 | const routes: Routes = [ 13 | { 14 | path: '', 15 | component: BlockingResolverPage, 16 | resolve: { 17 | data: BlockingResolver 18 | } 19 | } 20 | ]; 21 | 22 | @NgModule({ 23 | imports: [ 24 | CommonModule, 25 | FormsModule, 26 | IonicModule, 27 | HttpClientModule, 28 | RouterModule.forChild(routes) 29 | ], 30 | declarations: [BlockingResolverPage], 31 | providers: [BlockingResolver] 32 | }) 33 | export class BlockingResolverPageModule {} 34 | -------------------------------------------------------------------------------- /src/app/blocking-resolver/blocking-resolver.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Blocking Resolver 7 | 8 | 9 | 10 | 11 |
12 |

13 | Notice how the UX degrades when using Blocking Route Resolvers. 14 |

15 |
16 | 17 | 18 | Sample Image 19 | 20 | 21 |

22 | {{ item?.title }} 23 |

24 |

25 | {{ item?.description }} 26 |

27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /src/app/blocking-resolver/blocking-resolver.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ionicthemes/improved-ux-for-ionic-apps-with-skeleton-loading-screens/82ca2820262f384ab5b2595c9d369f9fe8c6ffe9/src/app/blocking-resolver/blocking-resolver.page.scss -------------------------------------------------------------------------------- /src/app/blocking-resolver/blocking-resolver.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | @Component({ 5 | selector: 'app-blocking-resolver', 6 | templateUrl: './blocking-resolver.page.html', 7 | styleUrls: ['./blocking-resolver.page.scss'], 8 | }) 9 | export class BlockingResolverPage implements OnInit { 10 | // We will assign data coming from the Route Resolver to this property 11 | routeResolveData: any; 12 | 13 | constructor(private route: ActivatedRoute) { } 14 | 15 | ngOnInit(): void { 16 | console.log('Blocking Resovlers - ngOnInit()'); 17 | 18 | if (this.route && this.route.data) { 19 | const dataObservable = this.route.data; 20 | console.log('Blocking Resovlers - Route Resolve Observable => dataObservable: ', dataObservable); 21 | 22 | if (dataObservable) { 23 | dataObservable.subscribe(observableValue => { 24 | const pageData: any = observableValue['data']; 25 | // tslint:disable-next-line:max-line-length 26 | console.log('Blocking Resovlers - Subscribe to dataObservable (will emmit just one value) => PageData (' + ((pageData && pageData.isShell) ? 'SHELL' : 'REAL') + '): ', pageData); 27 | if (pageData) { 28 | this.routeResolveData = pageData; 29 | } 30 | }); 31 | } else { 32 | console.warn('No dataObservable coming from Route Resolver data'); 33 | } 34 | } else { 35 | console.warn('No data coming from Route Resolver'); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/app/blocking-resolver/blocking.resolver.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Resolve } from '@angular/router'; 3 | import { LoadingController } from '@ionic/angular'; 4 | import { HttpClient } from '@angular/common/http'; 5 | 6 | import { defer, Observable } from 'rxjs'; 7 | import { finalize, tap, delay } from 'rxjs/operators'; 8 | 9 | @Injectable() 10 | export class BlockingResolver implements Resolve { 11 | private loadingElement: any; 12 | 13 | constructor( 14 | private loadingController: LoadingController, 15 | private http: HttpClient 16 | ) { } 17 | 18 | async presentLoader() { 19 | this.loadingElement = await this.loadingController.create({ 20 | message: 'Loading ...' 21 | }); 22 | 23 | await this.loadingElement.present(); 24 | } 25 | 26 | async dismissLoader() { 27 | if (this.loadingElement) { 28 | await this.loadingElement.dismiss(); 29 | } 30 | } 31 | 32 | // This should be in a separate service 33 | private getData(): Observable { 34 | const dataObservable = this.http.get('./assets/sample-data/page-data.json').pipe( 35 | tap(val => { 36 | console.log('getData STARTED'); 37 | }), 38 | delay(5000), 39 | finalize(() => { 40 | console.log('getData COMPLETED'); 41 | }) 42 | ); 43 | 44 | return dataObservable; 45 | } 46 | 47 | resolve() { 48 | // WITHOUT LOADING INDICATOR 49 | 50 | // Base Observable (where we get data from) 51 | // const dataObservable = this.getData(); 52 | 53 | // Basic Resolver that returns the base Observable 54 | // return dataObservable; 55 | 56 | 57 | // WITH LOADING INDICATOR 58 | 59 | // Base Observable (where we get data from) 60 | const dataObservable = this.getData().pipe( 61 | finalize(() => { 62 | console.log('dataObservable COMPLETED - HIDE LOADER'); 63 | this.dismissLoader(); 64 | }) 65 | ); 66 | 67 | const deferedObservable = defer(() => { 68 | // Will be logged at the moment of subscription 69 | console.log('dataObservable STARTED - SHOW LOADER'); 70 | this.presentLoader(); 71 | return dataObservable; 72 | }); 73 | 74 | // Basic Resolver that returns the base Observable 75 | return deferedObservable; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/app/components/components.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { IonicModule } from '@ionic/angular'; 4 | 5 | import { TextShellComponent } from './text-shell/text-shell.component'; 6 | import { ImageShellComponent } from './image-shell/image-shell.component'; 7 | 8 | @NgModule({ 9 | imports: [ 10 | CommonModule, 11 | IonicModule.forRoot(), 12 | ], 13 | declarations: [ 14 | TextShellComponent, 15 | ImageShellComponent 16 | ], 17 | exports: [ 18 | TextShellComponent, 19 | ImageShellComponent 20 | ], 21 | entryComponents: [], 22 | }) 23 | export class ComponentsModule {} 24 | -------------------------------------------------------------------------------- /src/app/components/image-shell/image-shell.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/app/components/image-shell/image-shell.component.scss: -------------------------------------------------------------------------------- 1 | :host { 2 | display: block; 3 | position: relative; 4 | height: 100%; 5 | width: 100%; 6 | overflow: hidden; 7 | transition: all ease-in-out .3s; 8 | z-index: 2; 9 | 10 | // Loading background 11 | &::before { 12 | content: ''; 13 | background-color: #EEE; 14 | position: absolute; 15 | top: 0; 16 | bottom: 0; 17 | left: 0; 18 | right: 0; 19 | } 20 | 21 | & > .spinner { 22 | display: block; 23 | position: absolute; 24 | top: calc(50% - calc(28px / 2)); 25 | left: calc(50% - calc(28px / 2)); 26 | width: 28px; 27 | height: 28px; 28 | font-size: 28px; 29 | line-height: 28px; 30 | color: #CCC; 31 | } 32 | 33 | & > .inner-img { 34 | transition: visibility 0s linear, opacity .5s linear; 35 | opacity: 0; 36 | visibility: hidden; 37 | width: 100%; 38 | height: 100%; 39 | } 40 | 41 | &.img-loaded { 42 | // Hide loading background once the image has loaded 43 | &::before { 44 | display: none; 45 | } 46 | 47 | & > .inner-img { 48 | opacity: 1; 49 | visibility: visible; 50 | } 51 | 52 | & > .spinner { 53 | display: none; 54 | visibility: hidden; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/app/components/image-shell/image-shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, HostBinding } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-image-shell', 5 | templateUrl: './image-shell.component.html', 6 | styleUrls: [ 7 | './image-shell.component.scss' 8 | ] 9 | }) 10 | export class ImageShellComponent { 11 | _src = ''; 12 | _alt = ''; 13 | 14 | @HostBinding('class.img-loaded') imageLoaded = false; 15 | 16 | @Input() 17 | set src(val: string) { 18 | this._src = (val !== undefined && val !== null) ? val : ''; 19 | } 20 | 21 | @Input() 22 | set alt(val: string) { 23 | this._alt = (val !== undefined && val !== null) ? val : ''; 24 | } 25 | 26 | constructor() {} 27 | 28 | _imageLoaded() { 29 | this.imageLoaded = true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/app/components/text-shell/text-shell.component.html: -------------------------------------------------------------------------------- 1 | {{ _data }} 2 | -------------------------------------------------------------------------------- /src/app/components/text-shell/text-shell.component.scss: -------------------------------------------------------------------------------- 1 | // Inspired in: https://stackoverflow.com/a/41096631/1116959 2 | @function randomNum($min, $max) { 3 | $rand: random(); 4 | $randomNum: $min + floor($rand * (($max - $min) + 1)); 5 | 6 | @return $randomNum; 7 | } 8 | 9 | // Inspired in: https://hugogiraudel.com/2013/08/08/advanced-sass-list-functions/ 10 | @function to-string($list, $glue: '', $is-nested: false) { 11 | $result: null; 12 | 13 | @for $i from 1 through length($list) { 14 | $e: nth($list, $i); 15 | 16 | @if type-of($e) == list { 17 | $result: $result#{to-string($e, $glue, true)}; 18 | } @else { 19 | $result: if( 20 | $i != length($list) or $is-nested, 21 | $result#{$e}#{$glue}, 22 | $result#{$e} 23 | ); 24 | } 25 | } 26 | 27 | @return $result; 28 | } 29 | 30 | @mixin background-height($property, $lines: 1) { 31 | $line-height: 16px; 32 | $line-spacing: 3px; 33 | 34 | #{$property}: calc((#{$line-height} * #{$lines}) + (#{$line-spacing} * (#{$lines} - 1))); 35 | } 36 | 37 | @mixin masked-lines-background($lines: 1) { 38 | $line-height: 16px; 39 | $line-spacing: 3px; 40 | $bg-color: transparent; 41 | $mask-color: #FFF; 42 | $line-bg-color: #FFF; 43 | $bg-y-pos: 0px; 44 | $rand-width: #{randomNum(85, 95)}; 45 | $bg-image: 'linear-gradient(to right, ' + $bg-color + ' ' + $rand-width + '% , ' + $mask-color + ' ' + $rand-width + '%)'; 46 | $bg-position: '0 ' + $bg-y-pos; 47 | $bg-size: '100% ' + $line-height; 48 | 49 | @if ($lines == 1) { 50 | background-image: #{$bg-image}; 51 | background-position: #{$bg-position}; 52 | background-size: #{$bg-size}; 53 | background-repeat: no-repeat; 54 | } @else { 55 | @for $i from 2 through $lines { 56 | // Add separator between lines 57 | $bg-image: append($bg-image, linear-gradient(to right, #{$line-bg-color} 100%, #{$line-bg-color} 100%)); 58 | // This linear-gradient as separator starts below the last line, 59 | // so we have to add $line-height to our y-pos pointer 60 | $bg-y-pos: calc((#{$line-height} * (#{$i} - 1)) + (#{$line-spacing} * (#{$i} - 2))); 61 | $bg-position: append($bg-position, '0 ' + $bg-y-pos); 62 | $bg-size: append($bg-size, '100% ' + $line-spacing); 63 | 64 | // Add new line 65 | // The last line should be narrow than the others 66 | @if ($i == $lines) { 67 | $rand-width: #{randomNum(30, 50)}; 68 | } @else { 69 | $rand-width: #{randomNum(60, 80)}; 70 | } 71 | $bg-image: append($bg-image, 'linear-gradient(to right, ' + $bg-color + ' ' + $rand-width + '% , ' + $mask-color + ' ' + $rand-width + '%)'); 72 | // This new line starts below the prviously added separator, 73 | // so we have to add $line-spacing to our y-pos pointer 74 | $bg-y-pos: calc((#{$line-height} * (#{$i} - 1)) + (#{$line-spacing} * (#{$i} - 1))); 75 | $bg-position: append($bg-position, '0 ' + $bg-y-pos); 76 | $bg-size: append($bg-size, '100% ' + $line-height); 77 | } 78 | 79 | background-image: #{to-string($bg-image, ', ')}; 80 | background-position: #{to-string($bg-position, ', ')}; 81 | background-size: #{to-string($bg-size, ', ')}; 82 | background-repeat: no-repeat; 83 | } 84 | 85 | @include background-height(min-height, $lines); 86 | } 87 | 88 | 89 | :host { 90 | display: block; 91 | position: relative; 92 | color: transparent; 93 | background-color: #FFF; 94 | transform-style: preserve-3d; 95 | // To fix 1px line misalignment in chrome: https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip 96 | // (I also noticed that if I set the color to a solid color instead of having opacity, the issue doesn't happen) 97 | background-clip: content-box; 98 | 99 | // The animation that goes beneath the masks 100 | &::before { 101 | content: ""; 102 | position: absolute; 103 | top: 0; 104 | left: 0; 105 | bottom: 0; 106 | right: 0; 107 | background: 108 | linear-gradient(to right, #EEE 8%, #DDD 18%, #EEE 33%); 109 | background-size: 800px 104px; 110 | animation: animateBackground 2s ease-in-out infinite; 111 | } 112 | 113 | // Calculate default height for 1 line 114 | @include background-height(min-height, 1); 115 | 116 | // The masks 117 | &::after { 118 | content: ""; 119 | position: absolute; 120 | top: 0; 121 | left: 0; 122 | bottom: 0; 123 | right: 0; 124 | 125 | // Default one line mask 126 | @include masked-lines-background(1); 127 | } 128 | 129 | // Support for [lines] attribute 130 | &[lines="2"] { 131 | // Calculate default height for 2 lines 132 | @include background-height(min-height, 2); 133 | 134 | &::after { 135 | @include masked-lines-background(2); 136 | } 137 | } 138 | 139 | &[lines="3"] { 140 | // Calculate default height for 3 lines 141 | @include background-height(min-height, 3); 142 | 143 | &::after { 144 | @include masked-lines-background(3); 145 | } 146 | } 147 | 148 | &.text-loaded { 149 | background: none; 150 | min-height: inherit; 151 | color: inherit; 152 | 153 | &::before, 154 | &::after { 155 | background: none; 156 | animation: 0; 157 | } 158 | } 159 | 160 | @keyframes animateBackground { 161 | 0%{ 162 | background-position: -468px 0 163 | } 164 | 165 | 100%{ 166 | background-position: 468px 0 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/app/components/text-shell/text-shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, HostBinding } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-text-shell', 5 | templateUrl: './text-shell.component.html', 6 | styleUrls: [ 7 | './text-shell.component.scss' 8 | ] 9 | }) 10 | export class TextShellComponent { 11 | _data: ''; 12 | 13 | @HostBinding('class.text-loaded') textLoaded = false; 14 | 15 | @Input() set data(val: any) { 16 | this._data = (val !== undefined && val !== null) ? val : ''; 17 | 18 | if (this._data && this._data !== '') { 19 | this.textLoaded = true; 20 | } else { 21 | this.textLoaded = false; 22 | } 23 | } 24 | 25 | constructor() { } 26 | } 27 | -------------------------------------------------------------------------------- /src/app/home/home.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { IonicModule } from '@ionic/angular'; 5 | import { RouterModule } from '@angular/router'; 6 | 7 | import { ComponentsModule } from '../components/components.module'; 8 | 9 | import { HomePage } from './home.page'; 10 | 11 | @NgModule({ 12 | imports: [ 13 | CommonModule, 14 | FormsModule, 15 | IonicModule, 16 | ComponentsModule, 17 | RouterModule.forChild([ 18 | { 19 | path: '', 20 | component: HomePage 21 | } 22 | ]) 23 | ], 24 | declarations: [HomePage] 25 | }) 26 | export class HomePageModule {} 27 | -------------------------------------------------------------------------------- /src/app/home/home.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Home 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Ionic 4 17 | Improving UX with App Shell Components 18 | 19 | 20 |

21 | Let me explain you the importance of adopting the App Shell pattern in your Ionic apps and show you how to implement it using Ionic 4, Angular 7 and some advanced CSS techniques. 22 |

23 |
24 |
25 | 26 | 27 | Route Resolves 28 | 29 |
30 |

31 | Angular Route Resolves are a special kind of route guards. They enable us to pre-fetch data from the server before navigating to a route. 32 |

33 |
34 |
35 |
Blocking Resolver
36 |

37 | By design, Angular Route Resolvers won't transition to the page until the resolved Observable completes. 38 |

39 |

40 | Use case: Let's suppose the backend is slow and takes 5 seconds to fetch data and return it to the client. The expected behavior for that scenario is that the page transition will be blocked for 5 seconds until the server sends data back to the client. 41 |

42 |

43 | A minimal improvement would be to show a loader while the resolved Observable completes. 44 |

45 |

46 | Blocking Resolver 47 |

48 |
49 |
50 |
Non Blocking Resolver
51 |

52 | You can avoid waiting for the Observable to complete and have instant page transitions. 53 |

54 |

55 | The trade-off of this approach is that the waiting time gets passed to the page component you are navigating to. 56 |

57 |

58 | Non Blocking Resolver 59 |

60 |

61 | This also means that you will be responsible for unhandled errors that may cause navigating to unavailable pages. 62 |

63 |
64 |
65 |
Progressive Shell Resolver
66 |

67 | By showing an app shell layout while loading data, we fix the waiting time issue caused when using non-blocking resolvers. 68 |

69 |

70 | Shell Resolver 71 |

72 |
73 | 74 | 75 | App Shell Approaches 76 | 77 |
78 |
Shell Overlays
79 |

80 | This is a straightforward approach. We define both shell and view layouts and switch/animate the transition between them when page/business/view data is available. 81 |

82 |
 83 | <ng-container *ngIf="!routeResolveData">
 84 |   <!-- Shell layout here -->
 85 | </ng-container>
 86 | 
 87 | <ng-container *ngIf="routeResolveData">
 88 |   <!-- View layout here -->
 89 | </ng-container>
 90 | 
91 |
92 |
93 |
Inline Shells
94 |

95 | This type of shells use the same layout (DOM elements) to present the loading state using the shell model and the real data once it’s available. 96 |

97 |
 98 | <ion-row>
 99 |   <ion-col size="4">
100 |     <app-image-shell class="add-spinner" [src]="routeResolveData?.image" [alt]="'Sample Image'"></app-image-shell>
101 |   </ion-col>
102 |   <ion-col size="8">
103 |     <h3>
104 |       <app-text-shell [data]="routeResolveData?.title"></app-text-shell>
105 |     </h3>
106 |     <p>
107 |       <app-text-shell lines="3" [data]="routeResolveData?.description"></app-text-shell>
108 |     </p>
109 |   </ion-col>
110 | </ion-row>
111 | 
112 |
113 | 114 | 115 | App Shell Components 116 | 117 |
118 |
Image Shell
119 |

120 | This component basically shows a loading indicator while fetching an image source. 121 |

122 |

123 | By listening to the (load) event attached to the <img/> element, once the image has loaded, we hide the loader. 124 |

125 |

126 | Note: As the [src] property is empty, the (load) event won't get triggered and then the component will remain in it's loading state. 127 |

128 |
129 | <app-image-shell [src]="" [alt]=""></app-image-shell>
130 | 
131 | 132 |
133 |
134 | 135 |
136 |
137 |
138 |
139 |
Text Shell
140 |

141 | This component basically works by wrapping the text node with a loading indicator while you are fetching data. 142 |

143 |

144 | While there are empty values the component adds some loading styles and animations. Whereas while there are non empty values, the loading state is removed. 145 |

146 |
147 | <app-text-shell [data]="" lines="3"></app-text-shell>
148 | 
149 |

150 | 151 |

152 |
153 | 154 | 155 | CSS Animations 156 | 157 |
158 |
No Animation
159 |

160 | Just the masked lines without any animation. 161 |

162 |
163 |
164 |
165 |

166 | Note: This approach plays well with use cases that require transparent backgrounds because it doesn't include an animation beneath. 167 |

168 |

169 | Just set the masks to transparent and voila. 170 |

171 |
172 |
173 |
174 |
175 |
176 |
Background Gradient
177 |

178 | This animation works by setting a background gradient beneath some mask elements. 179 |

180 |
181 |
182 |
183 |

184 | Side effect: This solution doesn’t play well if you require the text-shell to have a transparent background as the masks need a solid color to work properly. 185 |

186 |
187 |
188 |
189 |
190 |
191 |
Bouncing Lines Background
192 |

193 | This animation works by animating the background-size property to achieve a bouncing effect. 194 |

195 |
196 |
197 |
198 |

199 | Note: As we don’t use masks, this approach works well with use cases that require transparent backgrounds. 200 |

201 |
202 |
203 |
204 |
205 |
206 | -------------------------------------------------------------------------------- /src/app/home/home.page.scss: -------------------------------------------------------------------------------- 1 | .welcome-card ion-img { 2 | max-height: 35vh; 3 | overflow: hidden; 4 | } 5 | 6 | pre { 7 | font-size: 14px; 8 | background: #CCC; 9 | padding: 10px; 10 | } 11 | 12 | // Two lines text shell 13 | .text-shell { 14 | position: relative; 15 | min-height: 35px; /* (16px * 2) + 3px */ 16 | 17 | // No animation, default masked lines 18 | &::after { 19 | content: ""; 20 | position: absolute; 21 | top: 0; 22 | left: 0; 23 | bottom: 0; 24 | right: 0; 25 | background-repeat: no-repeat; 26 | background-image: 27 | /* First line: 95% width grey, 5% white mask */ 28 | linear-gradient(to right, #EEE 95%, transparent 95%), 29 | /* Separation between lines (a full width white line mask) */ 30 | linear-gradient(to right, transparent 100%, transparent 100%), 31 | /* Second line: 65% width grey, 35% white mask */ 32 | linear-gradient(to right, #EEE 65%, transparent 65%); 33 | 34 | background-size: 35 | /* First line: 100% width, 16px height */ 36 | 100% 16px, 37 | /* Separation between lines: a full width, 3px height line */ 38 | 100% 3px, 39 | /* Second line: 100% width, 16px height */ 40 | 100% 16px; 41 | 42 | background-position: 43 | /* First line: begins at left: 0, top: 0 */ 44 | 0 0px, 45 | /* Separation between lines: begins at left: 0, top: 16px (right below the first line) */ 46 | 0 16px, 47 | /* Second line: begins at left: 0, top: (16px + 3px) (right below the separation between lines) */ 48 | 0 19px; 49 | } 50 | 51 | &.gradient-animation { 52 | &::after { 53 | content: ""; 54 | position: absolute; 55 | top: 0; 56 | left: 0; 57 | bottom: 0; 58 | right: 0; 59 | background-repeat: no-repeat; 60 | background-image: 61 | /* First line: 95% width grey, 5% white mask */ 62 | linear-gradient(to right, transparent 95%, #FFF 95%), 63 | /* Separation between lines (a full width white line mask) */ 64 | linear-gradient(to right, #FFF 100%, #FFF 100%), 65 | /* Second line: 65% width grey, 35% white mask */ 66 | linear-gradient(to right, transparent 65%, #FFF 65%); 67 | 68 | background-size: 69 | /* First line: 100% width, 16px height */ 70 | 100% 16px, 71 | /* Separation between lines: a full width, 3px height line */ 72 | 100% 3px, 73 | /* Second line: 100% width, 16px height */ 74 | 100% 16px; 75 | 76 | background-position: 77 | /* First line: begins at left: 0, top: 0 */ 78 | 0 0px, 79 | /* Separation between lines: begins at left: 0, top: 16px (right below the first line) */ 80 | 0 16px, 81 | /* Second line: begins at left: 0, top: (16px + 3px) (right below the separation between lines) */ 82 | 0 19px; 83 | } 84 | 85 | // The animation that goes beneath the masks 86 | &::before { 87 | content: ""; 88 | position: absolute; 89 | top: 0; 90 | left: 0; 91 | bottom: 0; 92 | right: 0; 93 | background: 94 | linear-gradient(to right, #EEE 8%, #DDD 18%, #EEE 33%); 95 | background-size: 800px 104px; 96 | animation: animateBackground 2s ease-in-out infinite; 97 | } 98 | } 99 | 100 | &.bouncing-animation { 101 | &::after { 102 | content: ""; 103 | position: absolute; 104 | top: 0; 105 | left: 0; 106 | bottom: 0; 107 | right: 0; 108 | background-repeat: no-repeat; 109 | background-image: 110 | /* First line: 95% width grey */ 111 | linear-gradient(to right, #EEE 95%, transparent 95%), 112 | /* Separation between lines (a full width transparent line mask) */ 113 | linear-gradient(to right, transparent 100%, transparent 100%), 114 | /* Second line: 65% width grey */ 115 | linear-gradient(to right, #EEE 65%, transparent 65%); 116 | 117 | background-size: 118 | /* First line: 100% width, 16px height */ 119 | 100% 16px, 120 | /* Separation between lines: a full width, 3px height line */ 121 | 100% 3px, 122 | /* Second line: 100% width, 16px height */ 123 | 100% 16px; 124 | 125 | background-position: 126 | /* First line: begins at left: 0, top: 0 */ 127 | 0 0px, 128 | /* Separation between lines: begins at left: 0, top: 16px (right below the first line) */ 129 | 0 16px, 130 | /* Second line: begins at left: 0, top: (16px + 3px) (right below the separation between lines) */ 131 | 0 19px; 132 | 133 | animation-direction: alternate-reverse; 134 | animation-name: animateMultiLine; 135 | animation-fill-mode: forwards; 136 | animation-iteration-count: infinite; 137 | animation-timing-function: ease-in-out; 138 | animation-duration: 1s; 139 | 140 | @keyframes animateMultiLine { 141 | 0%{ 142 | background-size: 143 | /* First line animation initial state: 80% width, 16px height */ 144 | 80% 16px, 145 | /* Separation between lines: a full width, 3px height line */ 146 | 100% 3px, 147 | /* Second line animation initial state: 60% width, 16px height */ 148 | 60% 16px; 149 | } 150 | 151 | 100%{ 152 | background-size: 153 | /* First line animation final state: 100% width, 16px height */ 154 | 100% 16px, 155 | /* Separation between lines: a full width, 3px height line */ 156 | 100% 3px, 157 | /* Second line animation final state: 100% width, 16px height */ 158 | 100% 16px; 159 | } 160 | } 161 | } 162 | } 163 | 164 | @keyframes animateBackground { 165 | 0%{ 166 | background-position: -468px 0 167 | } 168 | 169 | 100%{ 170 | background-position: 468px 0 171 | } 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/app/home/home.page.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-home', 5 | templateUrl: 'home.page.html', 6 | styleUrls: ['home.page.scss'], 7 | }) 8 | export class HomePage { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/app/non-blocking-resolver/non-blocking-resolver.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | 7 | import { IonicModule } from '@ionic/angular'; 8 | 9 | import { NonBlockingResolverPage } from './non-blocking-resolver.page'; 10 | import { NonBlockingResolver } from './non-blocking.resolver'; 11 | 12 | const routes: Routes = [ 13 | { 14 | path: '', 15 | component: NonBlockingResolverPage, 16 | resolve: { 17 | data: NonBlockingResolver 18 | } 19 | } 20 | ]; 21 | 22 | @NgModule({ 23 | imports: [ 24 | CommonModule, 25 | FormsModule, 26 | IonicModule, 27 | HttpClientModule, 28 | RouterModule.forChild(routes) 29 | ], 30 | declarations: [NonBlockingResolverPage], 31 | providers: [NonBlockingResolver] 32 | }) 33 | export class NonBlockingResolverPageModule {} 34 | -------------------------------------------------------------------------------- /src/app/non-blocking-resolver/non-blocking-resolver.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Non Blocking Resolver 7 | 8 | 9 | 10 | 11 |
12 |

13 | Non Blocking Route Resolvers provide a better UX. Still the waiting time gets passed to the page component. 14 |

15 |
16 | 17 |
18 | 19 |

20 | You can show a loading indicator while fetching data from the backend. 21 |

22 |
23 |
24 | 25 | 26 | 27 | Sample Image 28 | 29 | 30 |

31 | {{ item?.title }} 32 |

33 |

34 | {{ item?.description }} 35 |

36 |
37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /src/app/non-blocking-resolver/non-blocking-resolver.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ionicthemes/improved-ux-for-ionic-apps-with-skeleton-loading-screens/82ca2820262f384ab5b2595c9d369f9fe8c6ffe9/src/app/non-blocking-resolver/non-blocking-resolver.page.scss -------------------------------------------------------------------------------- /src/app/non-blocking-resolver/non-blocking-resolver.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | @Component({ 5 | selector: 'app-non-blocking-resolver', 6 | templateUrl: './non-blocking-resolver.page.html', 7 | styleUrls: ['./non-blocking-resolver.page.scss'], 8 | }) 9 | export class NonBlockingResolverPage implements OnInit { 10 | // We will assign data coming from the Route Resolver to this property 11 | routeResolveData: any; 12 | 13 | constructor(private route: ActivatedRoute) { } 14 | 15 | ngOnInit(): void { 16 | console.log('NON Blocking Resovlers - ngOnInit()'); 17 | 18 | if (this.route && this.route.data) { 19 | // We resolved a promise for the data Observable 20 | const promiseObservable = this.route.data; 21 | console.log('NON Blocking Resovlers - Route Resolve Observable => promiseObservable: ', promiseObservable); 22 | 23 | if (promiseObservable) { 24 | promiseObservable.subscribe(promiseValue => { 25 | const dataObservable = promiseValue['data']; 26 | console.log('NON Blocking Resovlers - Subscribe to promiseObservable => dataObservable: ', dataObservable); 27 | 28 | if (dataObservable) { 29 | dataObservable.subscribe(observableValue => { 30 | const pageData: any = observableValue; 31 | // tslint:disable-next-line:max-line-length 32 | console.log('NON Blocking Resovlers - Subscribe to dataObservable (will emmit just one value) => PageData (' + ((pageData && pageData.isShell) ? 'SHELL' : 'REAL') + '): ', pageData); 33 | if (pageData) { 34 | this.routeResolveData = pageData; 35 | } 36 | }); 37 | } else { 38 | console.warn('No dataObservable coming from Route Resolver promiseObservable'); 39 | } 40 | }); 41 | } else { 42 | console.warn('No promiseObservable coming from Route Resolver data'); 43 | } 44 | } else { 45 | console.warn('No data coming from Route Resolver'); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/app/non-blocking-resolver/non-blocking.resolver.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Resolve } from '@angular/router'; 3 | import { HttpClient } from '@angular/common/http'; 4 | import { Observable } from 'rxjs'; 5 | import { tap, delay, finalize } from 'rxjs/operators'; 6 | 7 | @Injectable() 8 | export class NonBlockingResolver implements Resolve { 9 | 10 | constructor( 11 | private http: HttpClient 12 | ) {} 13 | 14 | // This should be in a separate service 15 | private getData(): Observable { 16 | const dataObservable = this.http.get('./assets/sample-data/page-data.json').pipe( 17 | tap(val => { 18 | console.log('getData STARTED'); 19 | }), 20 | delay(5000), 21 | finalize(() => { 22 | console.log('getData COMPLETED'); 23 | }) 24 | ); 25 | 26 | return dataObservable; 27 | } 28 | 29 | resolve() { 30 | // Base Observable (where we get data from) 31 | const dataObservable = this.getData(); 32 | 33 | // NON-BLOCKING RESOLVERS 34 | 35 | // Resolver using a ReplySubject that emits the base Observable and then completes 36 | // const subject = new ReplaySubject(); 37 | // subject.next(dataObservable); 38 | // subject.complete(); 39 | // return subject; 40 | 41 | // Resolver using an Observable that emits the base Observable and then completes 42 | // const observable = Observable.create((observer) => { 43 | // observer.next(dataObservable); 44 | // observer.complete(); 45 | // }); 46 | // return observable; 47 | 48 | // Resolver using a Promise that resolves the base Observable 49 | const observablePromise = new Promise((resolve, reject) => { 50 | resolve(dataObservable); 51 | }); 52 | return observablePromise; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/progressive-shell-resolver.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { Routes, RouterModule } from '@angular/router'; 5 | import { HttpClientModule } from '@angular/common/http'; 6 | 7 | import { IonicModule } from '@ionic/angular'; 8 | 9 | import { ProgressiveShellResolverPage } from './progressive-shell-resolver.page'; 10 | import { ProgressiveShellResolver } from './progressive-shell.resolver'; 11 | 12 | const routes: Routes = [ 13 | { 14 | path: '', 15 | component: ProgressiveShellResolverPage, 16 | resolve: { 17 | data: ProgressiveShellResolver 18 | } 19 | } 20 | ]; 21 | 22 | @NgModule({ 23 | imports: [ 24 | CommonModule, 25 | FormsModule, 26 | IonicModule, 27 | HttpClientModule, 28 | RouterModule.forChild(routes) 29 | ], 30 | declarations: [ProgressiveShellResolverPage], 31 | providers: [ProgressiveShellResolver] 32 | }) 33 | export class ProgressiveShellResolverPageModule {} 34 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/progressive-shell-resolver.page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Shell Resolver 7 | 8 | 9 | 10 | 11 |
12 |

13 | By following the App Shell pattern we can achieve awesome UX. 14 |

15 |
16 | 17 | 18 |
19 | Sample Image 20 |
21 |
22 | 23 |

24 | {{ item?.title }} 25 |

26 |

27 | {{ item?.description }} 28 |

29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/progressive-shell-resolver.page.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ionicthemes/improved-ux-for-ionic-apps-with-skeleton-loading-screens/82ca2820262f384ab5b2595c9d369f9fe8c6ffe9/src/app/progressive-shell-resolver/progressive-shell-resolver.page.scss -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/progressive-shell-resolver.page.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | 4 | import { SampleShellListingModel } from './sample-shell.model'; 5 | 6 | @Component({ 7 | selector: 'app-progressive-shell-resolver', 8 | templateUrl: './progressive-shell-resolver.page.html', 9 | styleUrls: [ 10 | './progressive-shell-resolver.page.scss', 11 | './shell-elements.scss' 12 | ] 13 | }) 14 | export class ProgressiveShellResolverPage implements OnInit { 15 | // We will assign data coming from the Route Resolver to this property 16 | routeResolveData: SampleShellListingModel; 17 | 18 | constructor( 19 | private route: ActivatedRoute 20 | ) { } 21 | 22 | ngOnInit(): void { 23 | console.log('Progressive Shell Resovlers - ngOnInit()'); 24 | 25 | if (this.route && this.route.data) { 26 | // We resolved a promise for the data Observable 27 | const promiseObservable = this.route.data; 28 | console.log('Progressive Shell Resovlers - Route Resolve Observable => promiseObservable: ', promiseObservable); 29 | 30 | if (promiseObservable) { 31 | promiseObservable.subscribe(promiseValue => { 32 | const dataObservable = promiseValue['data']; 33 | console.log('Progressive Shell Resovlers - Subscribe to promiseObservable => dataObservable: ', dataObservable); 34 | 35 | if (dataObservable) { 36 | dataObservable.subscribe(observableValue => { 37 | const pageData: SampleShellListingModel = observableValue; 38 | // tslint:disable-next-line:max-line-length 39 | console.log('Progressive Shell Resovlers - Subscribe to dataObservable (can emmit multiple values) => PageData (' + ((pageData && pageData.isShell) ? 'SHELL' : 'REAL') + '): ', pageData); 40 | // As we are implementing an App Shell architecture, pageData will be firstly an empty shell model, 41 | // and the real remote data once it gets fetched 42 | if (pageData) { 43 | this.routeResolveData = pageData; 44 | } 45 | }); 46 | } else { 47 | console.warn('No dataObservable coming from Route Resolver promiseObservable'); 48 | } 49 | }); 50 | } else { 51 | console.warn('No promiseObservable coming from Route Resolver data'); 52 | } 53 | } else { 54 | console.warn('No data coming from Route Resolver'); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/progressive-shell.resolver.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Resolve } from '@angular/router'; 3 | import { HttpClient } from '@angular/common/http'; 4 | 5 | import { Observable } from 'rxjs'; 6 | import { tap, delay, finalize } from 'rxjs/operators'; 7 | 8 | import { SampleShellListingModel } from './sample-shell.model'; 9 | import { ShellProvider } from './shell.provider'; 10 | 11 | @Injectable() 12 | export class ProgressiveShellResolver implements Resolve { 13 | 14 | constructor( 15 | private http: HttpClient 16 | ) {} 17 | 18 | // These should be in a separate service 19 | private getData(): Observable { 20 | const dataObservable = this.http.get('./assets/sample-data/page-data.json').pipe( 21 | tap(val => { 22 | console.log('getData STARTED'); 23 | }), 24 | delay(5000), 25 | finalize(() => { 26 | console.log('getData COMPLETED'); 27 | }) 28 | ); 29 | 30 | return dataObservable; 31 | } 32 | 33 | private getDataWithShell(): Observable { 34 | // Initialize the model specifying that it is a shell model 35 | const shellModel: SampleShellListingModel = new SampleShellListingModel(true); 36 | const dataObservable = this.getData(); 37 | 38 | const shellProvider = new ShellProvider( 39 | shellModel, 40 | dataObservable 41 | ); 42 | 43 | return shellProvider.observable; 44 | } 45 | 46 | resolve() { 47 | // Get the Shell Provider from the service 48 | const shellProviderObservable = this.getDataWithShell(); 49 | 50 | // Resolve with Shell Provider 51 | const observablePromise = new Promise((resolve, reject) => { 52 | resolve(shellProviderObservable); 53 | }); 54 | return observablePromise; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/sample-shell.model.ts: -------------------------------------------------------------------------------- 1 | export class SampleShellModel { 2 | image: string; 3 | title: string; 4 | description: string; 5 | } 6 | 7 | export class SampleShellListingModel { 8 | items: Array = [ 9 | new SampleShellModel(), 10 | new SampleShellModel(), 11 | new SampleShellModel() 12 | ]; 13 | 14 | constructor(readonly isShell: boolean) { } 15 | } 16 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/shell-elements.scss: -------------------------------------------------------------------------------- 1 | .image-shell { 2 | padding-bottom: 100%; 3 | height: 0px; 4 | position: relative; 5 | 6 | // The animation that goes beneath the masks 7 | &::before { 8 | content: ""; 9 | position: absolute; 10 | top: 0; 11 | left: 0; 12 | bottom: 0; 13 | right: 0; 14 | background: 15 | linear-gradient(to right, #EEE 8%, #DDD 18%, #EEE 33%); 16 | background-size: 800px 104px; 17 | animation: animateBackground 2s ease-in-out infinite; 18 | } 19 | 20 | & > img { 21 | position: absolute; 22 | top: 0px; 23 | left: 0px; 24 | right: 0px; 25 | bottom: 0px; 26 | 27 | &[src=""], 28 | &[src="null"] { 29 | display: none; 30 | } 31 | } 32 | } 33 | 34 | .text-shell { 35 | position: relative; 36 | 37 | // The animation that goes beneath the masks 38 | &::before { 39 | content: ""; 40 | position: absolute; 41 | top: 0; 42 | left: 0; 43 | bottom: 0; 44 | right: 0; 45 | background: 46 | linear-gradient(to right, #EEE 8%, #DDD 18%, #EEE 33%); 47 | background-size: 800px 104px; 48 | animation: animateBackground 2s ease-in-out infinite; 49 | } 50 | 51 | &.text-loaded { 52 | &::before, 53 | &::after { 54 | background: none !important; 55 | animation: 0 !important; 56 | } 57 | } 58 | } 59 | 60 | h3.text-shell { 61 | // The masks 62 | &::after { 63 | content: ""; 64 | position: absolute; 65 | top: 0; 66 | left: 0; 67 | bottom: 0; 68 | right: 0; 69 | background-repeat: no-repeat; 70 | background-image: 71 | /* First line: 95% width grey, 5% white mask */ 72 | linear-gradient(to right, transparent 95% , #FFF 95%); 73 | 74 | background-size: 75 | /* First line: 100% width, 16px height */ 76 | 100% 22px; 77 | 78 | background-position: 79 | /* First line: begins at left: 0, top: 0 */ 80 | 0 0px; 81 | } 82 | } 83 | 84 | p.text-shell { 85 | // The masks 86 | &::after { 87 | content: ""; 88 | position: absolute; 89 | top: 0; 90 | left: 0; 91 | bottom: 0; 92 | right: 0; 93 | background-repeat: no-repeat; 94 | background-image: 95 | /* First line: 95% width grey, 5% white mask */ 96 | linear-gradient(to right, transparent 95% , #FFF 95%), 97 | /* Separation between lines (a full width white line mask) */ 98 | linear-gradient(to right, #FFF 100%, #FFF 100%), 99 | /* Second line: 65% width grey, 35% white mask */ 100 | linear-gradient(to right, transparent 65% , #FFF 65%); 101 | 102 | background-size: 103 | /* First line: 100% width, 16px height */ 104 | 100% 16px, 105 | /* Separation between lines: a full width, 3px height line */ 106 | 100% 3px, 107 | /* Second line: 100% width, 16px height */ 108 | 100% 16px; 109 | 110 | background-position: 111 | /* First line: begins at left: 0, top: 0 */ 112 | 0 0px, 113 | /* Separation between lines: begins at left: 0, top: 16px (right below the first line) */ 114 | 0 16px, 115 | /* Second line: begins at left: 0, top: (16px + 3px) (right below the separation between lines) */ 116 | 0 19px; 117 | } 118 | } 119 | 120 | @keyframes animateBackground { 121 | 0%{ 122 | background-position: -468px 0 123 | } 124 | 125 | 100%{ 126 | background-position: 468px 0 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/app/progressive-shell-resolver/shell.provider.ts: -------------------------------------------------------------------------------- 1 | import { Observable, BehaviorSubject, forkJoin, of } from 'rxjs'; 2 | import { first, delay } from 'rxjs/operators'; 3 | 4 | export class ShellProvider { 5 | private _observable: Observable; 6 | 7 | // A Subject that requires an initial value and emits its current value to new subscribers 8 | // If we choose a BehaviorSubject, new subscribers will only get the latest value (real data). 9 | // This is useful for repeated use of the resolved data (navigate to a page, go back, navigate to the same page again) 10 | private _subject: BehaviorSubject; 11 | 12 | // We wait on purpose 2 secs on local environment when fetching from json to simulate the backend roundtrip. 13 | // However, in production you should set this delay to 0 in the environment.ts file. 14 | private networkDelay = 2000; 15 | // To debug shell styles, change configuration in the environment.ts file 16 | private debugMode = false; 17 | 18 | constructor(shellModel: T, dataObservable: Observable) { 19 | // tslint:disable-next-line:max-line-length 20 | const shellClassName = (shellModel && shellModel.constructor && shellModel.constructor.name) ? shellModel.constructor.name : 'No Class Name'; 21 | 22 | // tslint:disable-next-line:no-console 23 | console.time('[' + shellClassName + '] ShellProvider roundtrip'); 24 | // Set the shell model as the initial value 25 | this._subject = new BehaviorSubject(shellModel); 26 | 27 | const delayObservable = of(true).pipe( 28 | delay(this.networkDelay) 29 | // finalize(() => console.log('delayObservable COMPLETED')) 30 | ); 31 | 32 | dataObservable.pipe( 33 | first() // Prevent the need to unsubscribe because .first() completes the observable 34 | // finalize(() => console.log('dataObservable COMPLETED')) 35 | ); 36 | 37 | // Put both delay and data Observables in a forkJoin so they execute in parallel so that 38 | // the delay caused (on purpose) by the delayObservable doesn't get added to the time the dataObservable takes to complete 39 | const forkedObservables = forkJoin( 40 | delayObservable, 41 | dataObservable 42 | ) 43 | .pipe( 44 | // finalize(() => console.log('forkedObservables COMPLETED')) 45 | ) 46 | .subscribe(([delayValue, dataValue]: [boolean, T]) => { 47 | if (!this.debugMode) { 48 | this._subject.next(dataValue); 49 | // tslint:disable-next-line:no-console 50 | console.timeEnd('[' + shellClassName + '] ShellProvider roundtrip'); 51 | } 52 | }); 53 | 54 | this._observable = this._subject.asObservable(); 55 | } 56 | 57 | public get observable(): Observable { 58 | return this._observable; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/assets/icon/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ionicthemes/improved-ux-for-ionic-apps-with-skeleton-loading-screens/82ca2820262f384ab5b2595c9d369f9fe8c6ffe9/src/assets/icon/favicon.png -------------------------------------------------------------------------------- /src/assets/sample-data/page-data.json: -------------------------------------------------------------------------------- 1 | { 2 | "items": [ 3 | { 4 | "image": "https://lorempixel.com/200/200/people/1/", 5 | "title": "Sample Title", 6 | "description": "Sample Description" 7 | }, 8 | { 9 | "image": "https://lorempixel.com/200/200/people/2/", 10 | "title": "Sample Title", 11 | "description": "Sample Description" 12 | }, 13 | { 14 | "image": "https://lorempixel.com/200/200/people/3/", 15 | "title": "Sample Title", 16 | "description": "Sample Description" 17 | }, 18 | { 19 | "image": "https://lorempixel.com/200/200/people/4/", 20 | "title": "Sample Title", 21 | "description": "Sample Description" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /src/assets/shapes.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/global.scss: -------------------------------------------------------------------------------- 1 | // http://ionicframework.com/docs/theming/ 2 | @import '~@ionic/angular/css/core.css'; 3 | @import '~@ionic/angular/css/normalize.css'; 4 | @import '~@ionic/angular/css/structure.css'; 5 | @import '~@ionic/angular/css/typography.css'; 6 | 7 | @import '~@ionic/angular/css/padding.css'; 8 | @import '~@ionic/angular/css/float-elements.css'; 9 | @import '~@ionic/angular/css/text-alignment.css'; 10 | @import '~@ionic/angular/css/text-transformation.css'; 11 | @import '~@ionic/angular/css/flex-utils.css'; 12 | 13 | .demo-section { 14 | margin: 24px 16px; 15 | 16 | p { 17 | color: #666; 18 | line-height: 1.4; 19 | font-size: 14px; 20 | } 21 | 22 | code { 23 | color: #F92672; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Ionic App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10, IE11, and Chrome <55 requires all of the following polyfills. 22 | * This also includes Android Emulators with older versions of Chrome and Google Search/Googlebot 23 | */ 24 | 25 | // import 'core-js/es6/symbol'; 26 | // import 'core-js/es6/object'; 27 | // import 'core-js/es6/function'; 28 | // import 'core-js/es6/parse-int'; 29 | // import 'core-js/es6/parse-float'; 30 | // import 'core-js/es6/number'; 31 | // import 'core-js/es6/math'; 32 | // import 'core-js/es6/string'; 33 | // import 'core-js/es6/date'; 34 | // import 'core-js/es6/array'; 35 | // import 'core-js/es6/regexp'; 36 | // import 'core-js/es6/map'; 37 | // import 'core-js/es6/weak-map'; 38 | // import 'core-js/es6/set'; 39 | 40 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 41 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 42 | 43 | /** IE10 and IE11 requires the following for the Reflect API. */ 44 | // import 'core-js/es6/reflect'; 45 | 46 | /** 47 | * Web Animations `@angular/platform-browser/animations` 48 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 49 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 50 | */ 51 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 52 | 53 | /** 54 | * By default, zone.js will patch all possible macroTask and DomEvents 55 | * user can disable parts of macroTask/DomEvents patch by setting following flags 56 | * because those flags need to be set before `zone.js` being loaded, and webpack 57 | * will put import in the top of bundle, so user need to create a separate file 58 | * in this directory (for example: zone-flags.ts), and put the following flags 59 | * into that file, and then add the following code before importing zone.js. 60 | * import './zone-flags.ts'; 61 | * 62 | * The flags allowed in zone-flags.ts are listed here. 63 | * 64 | * The following flags will work for all browsers. 65 | * 66 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 67 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 68 | * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 69 | * 70 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 71 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 72 | * 73 | * (window as any).__Zone_enable_cross_context_check = true; 74 | * 75 | */ 76 | 77 | /*************************************************************************************************** 78 | * Zone JS is required by default for Angular itself. 79 | */ 80 | import 'zone.js/dist/zone'; // Included with Angular CLI. 81 | 82 | 83 | /*************************************************************************************************** 84 | * APPLICATION IMPORTS 85 | */ 86 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/theme/variables.scss: -------------------------------------------------------------------------------- 1 | // Ionic Variables and Theming. For more info, please see: 2 | // http://ionicframework.com/docs/theming/ 3 | 4 | /** Ionic CSS Variables **/ 5 | :root { 6 | /** primary **/ 7 | --ion-color-primary: #3880ff; 8 | --ion-color-primary-rgb: 56, 128, 255; 9 | --ion-color-primary-contrast: #ffffff; 10 | --ion-color-primary-contrast-rgb: 255, 255, 255; 11 | --ion-color-primary-shade: #3171e0; 12 | --ion-color-primary-tint: #4c8dff; 13 | 14 | /** secondary **/ 15 | --ion-color-secondary: #0cd1e8; 16 | --ion-color-secondary-rgb: 12, 209, 232; 17 | --ion-color-secondary-contrast: #ffffff; 18 | --ion-color-secondary-contrast-rgb: 255, 255, 255; 19 | --ion-color-secondary-shade: #0bb8cc; 20 | --ion-color-secondary-tint: #24d6ea; 21 | 22 | /** tertiary **/ 23 | --ion-color-tertiary: #7044ff; 24 | --ion-color-tertiary-rgb: 112, 68, 255; 25 | --ion-color-tertiary-contrast: #ffffff; 26 | --ion-color-tertiary-contrast-rgb: 255, 255, 255; 27 | --ion-color-tertiary-shade: #633ce0; 28 | --ion-color-tertiary-tint: #7e57ff; 29 | 30 | /** success **/ 31 | --ion-color-success: #10dc60; 32 | --ion-color-success-rgb: 16, 220, 96; 33 | --ion-color-success-contrast: #ffffff; 34 | --ion-color-success-contrast-rgb: 255, 255, 255; 35 | --ion-color-success-shade: #0ec254; 36 | --ion-color-success-tint: #28e070; 37 | 38 | /** warning **/ 39 | --ion-color-warning: #ffce00; 40 | --ion-color-warning-rgb: 255, 206, 0; 41 | --ion-color-warning-contrast: #ffffff; 42 | --ion-color-warning-contrast-rgb: 255, 255, 255; 43 | --ion-color-warning-shade: #e0b500; 44 | --ion-color-warning-tint: #ffd31a; 45 | 46 | /** danger **/ 47 | --ion-color-danger: #f04141; 48 | --ion-color-danger-rgb: 245, 61, 61; 49 | --ion-color-danger-contrast: #ffffff; 50 | --ion-color-danger-contrast-rgb: 255, 255, 255; 51 | --ion-color-danger-shade: #d33939; 52 | --ion-color-danger-tint: #f25454; 53 | 54 | /** dark **/ 55 | --ion-color-dark: #222428; 56 | --ion-color-dark-rgb: 34, 34, 34; 57 | --ion-color-dark-contrast: #ffffff; 58 | --ion-color-dark-contrast-rgb: 255, 255, 255; 59 | --ion-color-dark-shade: #1e2023; 60 | --ion-color-dark-tint: #383a3e; 61 | 62 | /** medium **/ 63 | --ion-color-medium: #989aa2; 64 | --ion-color-medium-rgb: 152, 154, 162; 65 | --ion-color-medium-contrast: #ffffff; 66 | --ion-color-medium-contrast-rgb: 255, 255, 255; 67 | --ion-color-medium-shade: #86888f; 68 | --ion-color-medium-tint: #a2a4ab; 69 | 70 | /** light **/ 71 | --ion-color-light: #f4f5f8; 72 | --ion-color-light-rgb: 244, 244, 244; 73 | --ion-color-light-contrast: #000000; 74 | --ion-color-light-contrast-rgb: 0, 0, 0; 75 | --ion-color-light-shade: #d7d8da; 76 | --ion-color-light-tint: #f5f6f9; 77 | } 78 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-redundant-jsdoc": true, 69 | "no-shadowed-variable": true, 70 | "no-string-literal": false, 71 | "no-string-throw": true, 72 | "no-switch-case-fall-through": true, 73 | "no-trailing-whitespace": true, 74 | "no-unnecessary-initializer": true, 75 | "no-unused-expression": true, 76 | "no-use-before-declare": true, 77 | "no-var-keyword": true, 78 | "object-literal-sort-keys": false, 79 | "one-line": [ 80 | true, 81 | "check-open-brace", 82 | "check-catch", 83 | "check-else", 84 | "check-whitespace" 85 | ], 86 | "prefer-const": true, 87 | "quotemark": [ 88 | true, 89 | "single" 90 | ], 91 | "radix": true, 92 | "semicolon": [ 93 | true, 94 | "always" 95 | ], 96 | "triple-equals": [ 97 | true, 98 | "allow-null-check" 99 | ], 100 | "typedef-whitespace": [ 101 | true, 102 | { 103 | "call-signature": "nospace", 104 | "index-signature": "nospace", 105 | "parameter": "nospace", 106 | "property-declaration": "nospace", 107 | "variable-declaration": "nospace" 108 | } 109 | ], 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "no-output-on-prefix": true, 121 | "use-input-property-decorator": true, 122 | "use-output-property-decorator": true, 123 | "use-host-property-decorator": true, 124 | "no-input-rename": true, 125 | "no-output-rename": true, 126 | "use-life-cycle-interface": true, 127 | "use-pipe-transform-interface": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------