简体   繁体   English

React-Native AlertIOS风格

[英]React-Native AlertIOS style

With AlertIOS , you can specify these button styles from my observations: 使用AlertIOS ,您可以从观察中指定以下按钮样式:

  1. "default" : blue color, normal text "default" :蓝色,普通文本
  2. "cancel" : blue color, bold text "cancel" :蓝色,粗体
  3. "destructive" : red color, normal text "destructive" :红色,普通文字

I'm assuming this naming convention corresponds with native UIAlertView style classes, is that right? 我假设此命名约定与本机UIAlertView样式类相对应,对吗? For alerts in my app, I want to emphasize positive actions with bold & blue text, so it is strange to me that these actions are set with a "cancel" style attribute. 对于我的应用中的警报,我想强调带有粗体和蓝色文本的积极操作,因此对这些操作设置为“取消”样式属性感到奇怪。 Is it just me or is the "cancel" style kind of a misnomer? 是我还是“取消”风格的用词不当?

AlertIOS.prompt("Enter a new name", null, [
  {
    text: "Update",
    style: "cancel",
    onPress: (name) => { this.updateName(name); }
  },
  {
    text: "Cancel",
    style: "destructive"
  }
]);

This naming convention is not related to UIAlertView (which is deprecated), but rather to its replacement - UIAlertController that was introduced in iOS8. 此命名约定与UIAlertView (已弃用)无关,而是与其替代UIAlertController中引入的UIAlertController有关。

Instead of specifying button titles when using UIAlertView , with UIAlertController you add actions. 在使用UIAlertViewUIAlertController时,无需指定按钮标题, UIAlertController添加操作。 Each action has its "action style" (deafult/cancel/destructive), which translates in the alert to a button with a corresponding style, defined by font and color. 每个动作都有其“动作样式”(默认/取消/破坏性),在警报中将其转换为具有由字体和颜色定义的相应样式的按钮。

The Apple documentation regarding the cancel style states: 关于取消样式的Apple文档指出:

Apply a style that indicates the action cancels the operation and leaves things unchanged 应用一种样式,该样式指示操作取消操作并使所有内容保持不变

I guess Apple thinks that this style emphasizes the fact that this operation will "leave things unchanged". 我猜苹果认为这种风格强调了这样的事实,即该操作将“使事情保持不变”。 Maybe to highlight to the user that this is his "way out" so they made it more prominent to the user. 也许向用户强调这是他的“出路”,所以他们使它对用户更加突出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM