This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo LivePhoto

允许在 iOS 上显示实时照片的库。

iOS
Included in Expo Go
Recommended version:
~58.0.4

安装

🌐 Installation

Terminal
- npx expo install expo-live-photo
- yarn expo install expo-live-photo
- pnpm expo install expo-live-photo
- bun expo install expo-live-photo

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

这里有一个简单的例子,展示了 expo-live-photo 与 expo-image-picker 的结合使用。

🌐 Here's a simple example of expo-live-photo usage combined with expo-image-picker.

LivePhoto
import * as ImagePicker from 'expo-image-picker'; import { LivePhotoAsset, LivePhotoView, LivePhotoViewType } from 'expo-live-photo'; import { useRef, useState } from 'react'; import { View, StyleSheet, Text, Button } from 'react-native'; export default function LivePhotoScreen() { const viewRef = useRef<LivePhotoViewType>(null); const [livePhoto, setLivePhoto] = useState<LivePhotoAsset | null>(null); const pickImage = async () => { const result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ['livePhotos'], }); if (!result.canceled && result.assets[0].pairedVideoAsset?.uri) { setLivePhoto({ photoUri: result.assets[0].uri, pairedVideoUri: result.assets[0].pairedVideoAsset.uri, }); } else { console.error('Failed to pick a live photo'); } }; if (!LivePhotoView.isAvailable()) { return ( <View style={styles.container}> <Text>expo-live-photo is not available on this platform 😕</Text> </View> ); } return ( <View style={styles.container}> <LivePhotoView ref={viewRef} source={livePhoto} style={[styles.livePhotoView, { display: livePhoto ? 'flex' : 'none' }]} onLoadComplete={() => { console.log('Live photo loaded successfully!'); }} onLoadError={error => { console.error('Failed to load the live photo: ', error.message); }} /> <View style={livePhoto ? styles.pickImageCollapsed : styles.pickImageExpanded}> <Button title={livePhoto ? 'Change image' : 'Pick an image'} onPress={pickImage} /> </View> <Button title="开始播放提示" onPress={() => viewRef.current?.startPlayback('hint')} /> <Button title="开始播放" onPress={() => viewRef.current?.startPlayback('full')} /> <Button title="停止播放" onPress={() => viewRef.current?.stopPlayback()} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', paddingVertical: 20, paddingHorizontal: 40, }, livePhotoView: { alignSelf: 'stretch', height: 300, }, pickImageExpanded: { alignSelf: 'stretch', height: 300, justifyContent: 'center', }, pickImageCollapsed: { marginVertical: 10, }, button: { marginVertical: 10, }, });

应用接口

🌐 API

import { LivePhotoView } from 'expo-live-photo';

No API data file found, sorry!