uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

ionic4 #259

Open uniquejava opened 5 years ago

uniquejava commented 5 years ago

优点:

真实设备上比如iphone调试太方便了 (safari)

坑点:: 使用form的地方, 要在xxx.module.ts中手动加入如下代码


@NgModule({
  imports: [CommonModule, FormsModule, ReactiveFormsModule, IonicModule, RouterModule.forChild(routes)],
  declarations: [Step2Page]
})
export class Step2PageModule {}

注意不是app.module.ts

每个用到module都要分别imports一次. 坑

uniquejava commented 5 years ago

setup

npm uninstall -g ionic
npm i -g ionic
ionic start hello blank --type=angular
cd hello
ionic serve

集成capacitor

ionic integrations enable capacitor
ionic build # and/or ionic build --production
ionic cap add ios
ionic cap sync
npx cap open ios

折行

在toast或actionsheet的header/title中使用换行符?

.toast-message {
  white-space: pre;
}

and \n for a line-break. 见: https://stackoverflow.com/questions/38597297/is-it-possible-to-have-newline-character-in-ionic2-toast

在capacitor项目中使用cordova pluglin

ionic cordova plugin add call-number

如下

npm i call-number
npm i @ionic-native/call-number

配色

src/theme/variables.scss

比如要把primary的颜色从默认的 #3880ff 改为 #38a1ea,一共要调整下面的4个值. 可以到这个页面计算出它的shade和tint颜色

// Ionic Variables and Theming. For more info, please see:
// http://ionicframework.com/docs/theming/

/** Ionic CSS Variables **/
:root {
  /** primary **/
  // --ion-color-primary: #3880ff;
  --ion-color-primary: #38a1ea;
  --ion-color-primary-rgb: 56, 161, 234;
  --ion-color-primary-contrast: #ffffff;
  --ion-color-primary-contrast-rgb: 255, 255, 255;
  // --ion-color-primary-shade: #3171e0;
  --ion-color-primary-shade: #318ece;
  // --ion-color-primary-tint: #4c8dff;
  --ion-color-primary-tint: #4caaec;

  /** secondary **/
  --ion-color-secondary: #0cd1e8;
  --ion-color-secondary-rgb: 12, 209, 232;
  --ion-color-secondary-contrast: #ffffff;
  --ion-color-secondary-contrast-rgb: 255, 255, 255;
  --ion-color-secondary-shade: #0bb8cc;
  --ion-color-secondary-tint: #24d6ea;

  /** tertiary **/
  --ion-color-tertiary: #7044ff;
  --ion-color-tertiary-rgb: 112, 68, 255;
  --ion-color-tertiary-contrast: #ffffff;
  --ion-color-tertiary-contrast-rgb: 255, 255, 255;
  --ion-color-tertiary-shade: #633ce0;
  --ion-color-tertiary-tint: #7e57ff;

  /** success **/
  --ion-color-success: #10dc60;
  --ion-color-success-rgb: 16, 220, 96;
  --ion-color-success-contrast: #ffffff;
  --ion-color-success-contrast-rgb: 255, 255, 255;
  --ion-color-success-shade: #0ec254;
  --ion-color-success-tint: #28e070;

  /** warning **/
  --ion-color-warning: #ffce00;
  --ion-color-warning-rgb: 255, 206, 0;
  --ion-color-warning-contrast: #ffffff;
  --ion-color-warning-contrast-rgb: 255, 255, 255;
  --ion-color-warning-shade: #e0b500;
  --ion-color-warning-tint: #ffd31a;

  /** danger **/
  --ion-color-danger: #f04141;
  --ion-color-danger-rgb: 245, 61, 61;
  --ion-color-danger-contrast: #ffffff;
  --ion-color-danger-contrast-rgb: 255, 255, 255;
  --ion-color-danger-shade: #d33939;
  --ion-color-danger-tint: #f25454;

  /** dark **/
  --ion-color-dark: #222428;
  --ion-color-dark-rgb: 34, 34, 34;
  --ion-color-dark-contrast: #ffffff;
  --ion-color-dark-contrast-rgb: 255, 255, 255;
  --ion-color-dark-shade: #1e2023;
  --ion-color-dark-tint: #383a3e;

  /** medium **/
  --ion-color-medium: #989aa2;
  --ion-color-medium-rgb: 152, 154, 162;
  --ion-color-medium-contrast: #ffffff;
  --ion-color-medium-contrast-rgb: 255, 255, 255;
  --ion-color-medium-shade: #86888f;
  --ion-color-medium-tint: #a2a4ab;

  /** light **/
  --ion-color-light: #f4f5f8;
  --ion-color-light-rgb: 244, 244, 244;
  --ion-color-light-contrast: #000000;
  --ion-color-light-contrast-rgb: 0, 0, 0;
  --ion-color-light-shade: #d7d8da;
  --ion-color-light-tint: #f5f6f9;
}

ion-toolbar {
  --background: linear-gradient(225deg, #38a3eb 0%, #2880c8 100%);
}

ion-button {
  --border-radius: 4px;
}

ion-content {
  --background: #f0f1f4;
  --ion-padding: 10px;
}

ion-item {
  --border-color: #bdcbd8;
}

ion-item.ion-dirty.ion-invalid {
  --border-color: var(--ion-color-danger);
}

ion-input input {
  --placeholder-color: var(--ion-color-dark);
  --placeholder-opacity: 0.5;
}

ion-checkbox {
  --border-color: #38a1ea;
  --border-width: 1px;
  --border-radius: 2px;
  --size: 14px;
}