This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 铰链
一个提供安卓折叠屏和iPhone Duo设备铰链角度及状态的库。
expo-hinge 可以让整个应用访问可折叠设备的铰链,比如 Android 可折叠手机或 iPhone Duo。它会报告铰链的角度(以度为单位)以及铰链是关闭、部分打开,还是完全打开。在 Android 上,铰链角度传感器提供角度信息,而 Jetpack WindowManager 的 FoldingFeature 提供状态信息。在 iOS 上,应用窗口上的 UIHingeInteraction 提供这些数值。如果你想在单个 SwiftUI 视图中响应铰链,可以使用 @expo/ui 的 onHingeChange 修饰器。
重要 在 Android 上,铰链更新需要 Android 11(API 级别 30)或更高版本。在 iOS 上,需要 iOS 27.1 或更高版本,并且构建版本需使用 Xcode 27.1 或更高版本。在较旧的构建和系统上,或者在没有铰链的设备上,铰链为
null。使用铰链状态来处理交互和效果,而不是布局。
Android上的状态
🌐 Status on Android
Android 没有公开的 API 来报告合上状态,所以在 Android 上状态永远不会是 closed。Android 只有在应用窗口跨折叠时才会报告铰链状态。否则,比如在设备关闭时的外屏上,状态是 unknown,但 Android 仍然会报告角度。要在 Android 上检测关闭的设备,可以检查角度是否接近 0。选择一个适合你应用的阈值,因为设备厂商会定义自己的范围。
🌐 Android has no public API that reports a closed hinge, so the status is never closed on Android. Android reports the hinge state only while the app's window spans the fold. Otherwise, such as on the outer screen of a closed device, the status is unknown, but Android still reports the angle. To detect a closed device on Android, check for an angle near 0. Choose a threshold that suits your app, because device makers define their own ranges.
安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
import { useHinge } from 'expo-hinge'; import { StyleSheet, Text, View } from 'react-native'; export default function App() { const hinge = useHinge(); return ( <View style={styles.container}> <Text>{hinge ? `${hinge.status} at ${Math.round(hinge.angle)}°` : 'No hinge'}</Text> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, });
应用接口
🌐 API
import * as Hinge from 'expo-hinge';
No API data file found, sorry!