跳到主要內容

ActionSheetIOS

顯示 iOS 原生 Action Sheet 組件。

範例

參考

方法

showActionSheetWithOptions()

tsx
static showActionSheetWithOptions: (
options: ActionSheetIOSOptions,
callback: (buttonIndex: number) => void,
);

顯示 iOS 動作選單。 options 物件必須包含以下一或多個:

  • options (字串陣列) - 按鈕標題列表 (必填)
  • cancelButtonIndex (整數) - options 中取消按鈕的索引
  • cancelButtonTintColor (字串) - 用於更改取消按鈕文字顏色的顏色
  • destructiveButtonIndex (整數或整數陣列) - options 中破壞性按鈕的索引
  • title (字串) - 顯示在動作選單上方的標題
  • message (字串) - 顯示在標題下方的訊息
  • anchor (數字) - 動作選單應錨定的節點 (用於 iPad)
  • tintColor (字串) - 用於非破壞性按鈕標題的顏色
  • disabledButtonIndices (數字陣列) - 應停用的按鈕索引列表
  • userInterfaceStyle (字串) - 用於動作選單的介面樣式,可以設定為 lightdark,否則將使用預設系統樣式

「回呼」函數接受一個參數,即所選項目的從零開始的索引。

最小範例

tsx
ActionSheetIOS.showActionSheetWithOptions(
{
options: ['Cancel', 'Remove'],
destructiveButtonIndex: 1,
cancelButtonIndex: 0,
},
buttonIndex => {
if (buttonIndex === 1) {
/* destructive action */
}
},
);

dismissActionSheet()

tsx
static dismissActionSheet();

關閉最上層顯示的 iOS 動作選單,如果沒有動作選單顯示,則會顯示警告。


showShareActionSheetWithOptions()

tsx
static showShareActionSheetWithOptions: (
options: ShareActionSheetIOSOptions,
failureCallback: (error: Error) => void,
successCallback: (success: boolean, method: string) => void,
);

顯示 iOS 分享表單。 options 物件應包含 messageurl 的其中一個或兩個,並且可以額外具有 subjectexcludedActivityTypes

  • url (字串) - 要分享的 URL
  • message (字串) - 要分享的訊息
  • subject (字串) - 訊息的主旨
  • excludedActivityTypes (陣列) - 從 ActionSheet 中排除的活動類型

注意: 如果 url 指向本機檔案,或是 base64 編碼的 uri,它指向的檔案將會被載入並直接分享。 透過這種方式,您可以分享圖片、影片、PDF 檔案等。 如果 url 指向遠端檔案或位址,則必須符合 RFC 2396 中描述的 URL 格式。 例如,沒有正確協定 (HTTP/HTTPS) 的網頁 URL 將不會被分享。

「failureCallback」函數接受一個參數,即錯誤物件。 此物件上定義的唯一屬性是類型為 string 的選用 stack 屬性。

「successCallback」函數接受兩個參數

  • 一個布林值,表示成功或失敗
  • 一個字串,在成功的情況下,表示分享的方法