咨询:Expo SDK v29.0.0联系人原生模态框API为何未在文档中找到?
Great question! I totally get the confusion here — when Expo SDK 29 first launched, that native contact modal feature was a bit hidden in the existing Contacts API, and the official docs didn’t highlight it super clearly at first.
You didn’t miss anything major; those modal functions are actually built into two under-documented (at the time) methods of the expo-contacts module:
- View/Select Contacts: Use
Contacts.pickContactAsync()— this triggers the system’s native contact picker modal, lets users select a contact, and returns the full contact data once they confirm. - Create/Edit Contacts: Use
Contacts.presentFormAsync(contactData)— pass in a contact object (empty for a new contact, or an existing contact to edit), and it’ll open the system’s native contact edit/form modal. After the user finishes editing, it returns the updated contact details (or confirms if the user canceled the action).
Here’s a quick example to show how to use the create/edit modal:
import * as Contacts from 'expo-contacts'; async function openContactForm() { // First, request necessary permissions const { status } = await Contacts.requestPermissionsAsync(); if (status !== 'granted') { alert('Need contacts permission to use this feature!'); return; } // Open modal to create a new contact (pass existing contact to edit) const result = await Contacts.presentFormAsync({ firstName: 'Jane', lastName: 'Smith', phoneNumbers: [{ number: '555-1234' }], }); if (!result.canceled) { console.log('Updated/created contact:', result.contact); } else { console.log('User canceled the contact form'); } }
A heads-up: If you’re looking at older versions of the Expo docs, these methods might not be prominently featured, but they’ve been part of the expo-contacts module since SDK 29. Double-check the latest version of the docs for full details on parameters and return values.
内容的提问来源于stack exchange,提问作者arnaudambro

