Skip to content

Commit

Permalink
fix(platform): better detect platforms + css API
Browse files Browse the repository at this point in the history
fixes #15165
fixes #15116
  • Loading branch information
manucorporat committed Aug 25, 2018
1 parent 70a38ac commit 3ffa3cd
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 300 deletions.
45 changes: 4 additions & 41 deletions angular/src/providers/platform.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { EventEmitter, Injectable } from '@angular/core';
import { PlatformConfig, detectPlatforms } from '@ionic/core';
import { Platforms, getPlatforms, isPlatform } from '@ionic/core';
import { proxyEvent } from '../util/util';


@Injectable()
export class Platform {

private _platforms = detectPlatforms(window);
private _readyPromise: Promise<string>;

/**
Expand Down Expand Up @@ -94,20 +93,8 @@ export class Platform {
* | electron | in Electron on a desktop device. |
*
*/
is(platformName: string): boolean {
return this._platforms.some(p => p.name === platformName);
}

/**
* @param win the window object
* @param platforms an array of platforms (platform configs)
* to get the appropriate platforms according to the configs provided.
* @description
* Detects the platforms using window and the platforms config provided.
* Populates the platforms array so they can be used later on for platform detection.
*/
detectPlatforms(platforms: PlatformConfig[]) {
return detectPlatforms(window, platforms);
is(platformName: Platforms): boolean {
return isPlatform(window, platformName);
}

/**
Expand All @@ -130,32 +117,9 @@ export class Platform {
* ```
*/
platforms(): string[] {
return this._platforms.map(platform => platform.name);
}

/**
* Returns an object containing version information about all of the platforms.
*
* ```
* import { Platform } from 'ionic-angular';
*
* @Component({...})
* export MyPage {
* constructor(public platform: Platform) {
* // This will print an object containing
* // all of the platforms and their versions
* console.log(platform.versions());
* }
* }
* ```
*
* @returns An object containing all of the platforms and their versions.
*/
versions(): PlatformConfig[] {
return this._platforms.slice();
return getPlatforms(window);
}


ready(): Promise<string> {
return this._readyPromise;
}
Expand All @@ -164,7 +128,6 @@ export class Platform {
return document.dir === 'rtl';
}


/**
* Get the query string parameter
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/action-sheet/action-sheet.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

.action-sheet-wrapper {
@include margin(var(--ion-safe-area-top), auto, var(--ion-safe-area-bottom), auto);
@include margin(var(--ion-safe-area-top, 0), auto, var(--ion-safe-area-bottom, 0), auto);
}


Expand Down
25 changes: 1 addition & 24 deletions core/src/components/app/app.scss
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@

ion-app.is-device {
html.plt-mobile ion-app {
user-select: none;
}

ion-app.statusbar-padding {
--ion-safe-area-top: 20px;
}

// TODO: remove once Safari 11.2 dies
@supports (padding-top: constant(safe-area-inset-top)) {
ion-app.statusbar-padding {
--ion-safe-area-top: constant(safe-area-inset-top);
--ion-safe-area-bottom: constant(safe-area-inset-bottom);
--ion-safe-area-left: constant(safe-area-inset-left);
--ion-safe-area-right: constant(safe-area-inset-right);
}
}

@supports (padding-top: env(safe-area-inset-top)) {
ion-app.statusbar-padding {
--ion-safe-area-top: env(safe-area-inset-top);
--ion-safe-area-bottom: env(safe-area-inset-bottom);
--ion-safe-area-left: env(safe-area-inset-left);
--ion-safe-area-right: env(safe-area-inset-right);
}
}
26 changes: 8 additions & 18 deletions core/src/components/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
import { Component, Element, Prop, QueueApi } from '@stencil/core';

import { Config } from '../../interface';
import { isDevice, isHybrid, isStandaloneMode, needInputShims } from '../../utils/platform';
import { isPlatform } from '../../utils/platform';

@Component({
tag: 'ion-app',
styleUrl: 'app.scss'
})
export class App {

private isDevice = false;

@Element() el!: HTMLElement;

@Prop({ context: 'window' }) win!: Window;
@Prop({ context: 'config' }) config!: Config;
@Prop({ context: 'queue' }) queue!: QueueApi;

componentWillLoad() {
this.isDevice = this.config.getBoolean('isDevice', isDevice(this.win));
}

componentDidLoad() {
setTimeout(() => {
importTapClick(this.win);
importInputShims(this.win, this.config);
importStatusTap(this.win, this.isDevice, this.queue);
importStatusTap(this.win, this.queue);
}, 32);
}

hostData() {
const hybrid = isHybrid(this.win);
const isStandalone = isStandaloneMode(this.win);
const statusbarPadding = this.config.getBoolean('statusbarPadding', hybrid || isStandalone);

return {
class: {
'ion-page': true,
'is-device': this.isDevice,
'is-hydrid': hybrid,
'is-standalone': isStandalone,
'statusbar-padding': statusbarPadding
}
};
}
}

async function importStatusTap(win: Window, device: boolean, queue: QueueApi) {
if (device) {
async function importStatusTap(win: Window, queue: QueueApi) {
if (isPlatform(win, 'hybrid')) {
(await import('../../utils/status-tap')).startStatusTap(win, queue);
}
}
Expand All @@ -62,3 +48,7 @@ async function importInputShims(win: Window, config: Config) {
(await import('../../utils/input-shims/input-shims')).startInputShims(win.document, config);
}
}

function needInputShims(win: Window) {
return isPlatform(win, 'ios') && isPlatform(win, 'mobile');
}
8 changes: 4 additions & 4 deletions core/src/components/col/col.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Element, Listen, Prop } from '@stencil/core';

import { isMatch } from '../../utils/media';
import { matchBreakpoint } from '../../utils/media';

const SUPPORTS_VARS = !!(CSS && CSS.supports && CSS.supports('--a', '0'));
const BREAKPOINTS = ['', 'xs', 'sm', 'md', 'lg', 'xl'];
Expand All @@ -11,7 +11,7 @@ const BREAKPOINTS = ['', 'xs', 'sm', 'md', 'lg', 'xl'];
shadow: true
})
export class Col {
[key: string]: any;
@Prop({ context: 'window' }) win!: Window;

@Element() el!: HTMLStencilElement;

Expand Down Expand Up @@ -166,11 +166,11 @@ export class Col {
let matched;

for (const breakpoint of BREAKPOINTS) {
const matches = isMatch(breakpoint);
const matches = matchBreakpoint(this.win, breakpoint);

// Grab the value of the property, if it exists and our
// media query matches we return the value
const columns = this[property + breakpoint.charAt(0).toUpperCase() + breakpoint.slice(1)];
const columns = (this as any)[property + breakpoint.charAt(0).toUpperCase() + breakpoint.slice(1)];

if (matches && columns !== undefined) {
matched = columns;
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/footer/footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ ion-footer {
}

ion-footer ion-toolbar:last-child {
padding-bottom: var(--ion-safe-area-bottom);
padding-bottom: var(--ion-safe-area-bottom, 0);
}
7 changes: 2 additions & 5 deletions core/src/components/hide-when/hide-when.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Component, Element, Listen, Prop, State } from '@stencil/core';

import { Config, Mode } from '../../interface';
import { DisplayWhen, PLATFORM_CONFIGS, PlatformConfig, detectPlatforms, updateTestResults } from '../../utils/show-hide-when-utils';
import { DisplayWhen, updateTestResults } from '../../utils/show-hide-when-utils';

@Component({
tag: 'ion-hide-when',
styleUrl: './hide-when.scss'
})
export class HideWhen implements DisplayWhen {

calculatedPlatforms!: PlatformConfig[];

@Element() element!: HTMLElement;
@Prop({ context: 'config' }) config!: Config;
@Prop({ context: 'window' }) win!: Window;
Expand Down Expand Up @@ -52,13 +50,12 @@ export class HideWhen implements DisplayWhen {
@State() passesTest = false;

componentWillLoad() {
this.calculatedPlatforms = detectPlatforms(this.win, PLATFORM_CONFIGS);
this.onResize();
}

@Listen('window:resize')
onResize() {
updateTestResults(this);
this.passesTest = updateTestResults(this);
}

hostData() {
Expand Down
14 changes: 3 additions & 11 deletions core/src/components/nav/nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -797,29 +797,21 @@ export class Nav implements NavOutlet {

...opts
};
const trns = await transition(animationOpts);
return this.transitionFinish(trns, enteringView, leavingView, opts);
const { hasCompleted } = await transition(animationOpts);
return this.transitionFinish(hasCompleted, enteringView, leavingView, opts);
}

private transitionFinish(
trans: Animation | null,
hasCompleted: boolean,
enteringView: ViewController,
leavingView: ViewController | undefined,
opts: NavOptions
): NavResult {
const hasCompleted = trans ? trans.hasCompleted : true;

const cleanupView = hasCompleted ? enteringView : leavingView;
if (cleanupView) {
this.cleanup(cleanupView);
}

// this is the root transition
// it's safe to destroy this transition
if (trans) {
trans.destroy();
}

return {
hasCompleted,
requiresTransition: true,
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/picker/picker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ion-picker {

justify-content: center;

margin-bottom: var(--ion-safe-area-bottom);
margin-bottom: var(--ion-safe-area-bottom, 0);

contain: strict;
overflow: hidden;
Expand Down
6 changes: 2 additions & 4 deletions core/src/components/show-when/show-when.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Element, Listen, Prop, State } from '@stencil/core';

import { Config, Mode } from '../../interface';
import { DisplayWhen, PLATFORM_CONFIGS, PlatformConfig, detectPlatforms, updateTestResults } from '../../utils/show-hide-when-utils';
import { DisplayWhen, updateTestResults } from '../../utils/show-hide-when-utils';

@Component({
tag: 'ion-show-when',
Expand All @@ -12,7 +12,6 @@ export class ShowWhen implements DisplayWhen {
@Element() element?: HTMLElement;

@Prop({ context: 'config' }) config!: Config;
@Prop({ context: 'platforms' }) calculatedPlatforms!: PlatformConfig[];
@Prop({ context: 'window' }) win!: Window;

/**
Expand Down Expand Up @@ -52,13 +51,12 @@ export class ShowWhen implements DisplayWhen {
@State() passesTest = false;

componentWillLoad() {
this.calculatedPlatforms = detectPlatforms(this.win, PLATFORM_CONFIGS);
this.onResize();
}

@Listen('window:resize')
onResize() {
updateTestResults(this);
this.passesTest = updateTestResults(this);
}

hostData() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/tabbar/tabbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

:host(.placement-bottom) {
padding-bottom: var(--ion-safe-area-bottom);
padding-bottom: var(--ion-safe-area-bottom, 0);
}


Expand Down
4 changes: 2 additions & 2 deletions core/src/components/toast/toast.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
}

.toast-md .toast-wrapper.toast-top {
padding-top: var(--ion-safe-area-top);
padding-top: var(--ion-safe-area-top, 0);
}

.toast-md .toast-wrapper.toast-bottom {
padding-bottom: var(--ion-safe-area-bottom);
padding-bottom: var(--ion-safe-area-bottom, 0);
}

.toast-md .toast-wrapper.toast-middle {
Expand Down
26 changes: 26 additions & 0 deletions core/src/css/structure.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,29 @@ ion-toast-controller,
.ion-page-invisible {
opacity: 0;
}

html.plt-ios.plt-hybrid, html.plt-ios.plt-pwa {
--ion-statusbar-padding: 20px;
}
html {
--ion-safe-area-top: var(--ion-statusbar-padding);
}

// TODO: remove once Safari 11.2 dies
@supports (padding-top: constant(safe-area-inset-top)) {
html {
--ion-safe-area-top: constant(safe-area-inset-top);
--ion-safe-area-bottom: constant(safe-area-inset-bottom);
--ion-safe-area-left: constant(safe-area-inset-left);
--ion-safe-area-right: constant(safe-area-inset-right);
}
}

@supports (padding-top: env(safe-area-inset-top)) {
html {
--ion-safe-area-top: env(safe-area-inset-top);
--ion-safe-area-bottom: env(safe-area-inset-bottom);
--ion-safe-area-left: env(safe-area-inset-left);
--ion-safe-area-right: env(safe-area-inset-right);
}
}
2 changes: 0 additions & 2 deletions core/src/global/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export interface IonicConfig {
mode?: Mode;
persistConfig?: boolean;

isDevice?: boolean;
statusbarPadding?: boolean;
inputShims?: boolean;
backButtonIcon?: string;
backButtonText?: string;
Expand Down
Loading

0 comments on commit 3ffa3cd

Please sign in to comment.