改善用户体验
配置文本输入
¥Configure text inputs
在触摸手机上输入文本是一个挑战 - 小屏幕,软件键盘。但根据你需要的数据类型,你可以通过正确配置文本输入来使其变得更容易:
¥Entering text on touch phone is a challenge - small screen, software keyboard. But based on what kind of data you need, you can make it easier by properly configuring the text inputs:
-
自动聚焦第一个字段
¥Focus the first field automatically
-
使用占位符文本作为预期数据格式的示例
¥Use placeholder text as an example of expected data format
-
启用或禁用自动大写和自动更正
¥Enable or disable autocapitalization and autocorrect
-
选择键盘类型(例如电子邮件、数字)
¥Choose keyboard type (e.g. email, numeric)
-
确保返回按钮聚焦下一个字段或提交表单
¥Make sure the return button focuses the next field or submits the form
查看 TextInput
文档 了解更多配置选项。
¥Check out TextInput
docs for more configuration options.
- TypeScript
- JavaScript
键盘可见时管理布局
¥Manage layout when keyboard is visible
软件键盘几乎占据了屏幕的一半。如果你的交互元素可以被键盘覆盖,请确保仍然可以使用 KeyboardAvoidingView
组件 访问它们。
¥Software keyboard takes almost half of the screen. If you have interactive elements that can get covered by the keyboard, make sure they are still accessible by using the KeyboardAvoidingView
component.
- TypeScript
- JavaScript
使可点击区域更大
¥Make tappable areas larger
在手机上按下按钮时很难非常精确。确保所有交互元素均为 44x44 或更大。一种方法是为元素留出足够的空间,padding
、minWidth
和 minHeight
样式值对此很有用。或者,你可以使用 hitSlop
属性 来增加交互区域而不影响布局。这是一个演示:
¥On mobile phones it's hard to be very precise when pressing buttons. Make sure all interactive elements are 44x44 or larger. One way to do this is to leave enough space for the element, padding
, minWidth
and minHeight
style values can be useful for that. Alternatively, you can use hitSlop
prop to increase interactive area without affecting the layout. Here's a demo:
使用 Android 波纹
¥Use Android Ripple
Android API 21+ 使用材料设计波纹在用户触摸屏幕上的可交互区域时向用户提供反馈。React Native 通过 TouchableNativeFeedback
组件 公开了这一点。使用这种可触摸效果而不是不透明或高亮通常会让你的应用感觉更适合平台。也就是说,使用它时需要小心,因为它不适用于 iOS 或 Android API < 21,因此你需要回退到使用 iOS 上的其他 Touchable 组件之一。你可以使用像 react-native-platform-touchable 这样的库来为你处理平台差异。
¥Android API 21+ uses the material design ripple to provide user with feedback when they touch an interactable area on the screen. React Native exposes this through the TouchableNativeFeedback
component. Using this touchable effect instead of opacity or highlight will often make your app feel much more fitting on the platform. That said, you need to be careful when using it because it doesn't work on iOS or on Android API < 21, so you will need to fallback to using one of the other Touchable components on iOS. You can use a library like react-native-platform-touchable to handle the platform differences for you.
屏幕方向锁定
¥Screen orientation lock
默认情况下,多个屏幕方向应该可以正常工作,除非你使用 Dimensions
API 并且不处理方向更改。如果你不想支持多种屏幕方向,可以将屏幕方向锁定为纵向或横向。
¥Multiple screen orientations should work fine by default unless you're using Dimensions
API and don't handle orientation changes. If you don't want to support multiple screen orientations, you can lock the screen orientation to either portrait or landscape.
在 iOS 上,在 Xcode 的“常规”选项卡和“部署信息”部分中启用你想要支持的设备方向(确保在进行更改时从“设备”菜单中选择了 iPhone)。对于 Android,打开 AndroidManifest.xml 文件,然后在活动元素中添加 'android:screenOrientation="portrait"'
以锁定为纵向,或添加 'android:screenOrientation="landscape"'
以锁定为横向。
¥On iOS, in the General tab and Deployment Info section of Xcode enable the Device Orientation you want to support (ensure you have selected iPhone from the Devices menu when making the changes). For Android, open the AndroidManifest.xml file and within the activity element add 'android:screenOrientation="portrait"'
to lock to portrait or 'android:screenOrientation="landscape"'
to lock to landscape.
了解更多
¥Learn more
材料设计 和 人机界面指南 是了解更多有关移动平台设计的重要资源。
¥Material Design and Human Interface Guidelines are great resources for learning more about designing for mobile platforms.