native.showPopup() — Activity Popup

Type function
Library native.*
Return value none
Revision Release 2022.3683
Keywords native, showPopup, activity

Overview

Displays the activity popup window which corresponds to UIActivityViewController on iOS. The set of activities depends on the items you specify.

Syntax

native.showPopup( name, options )
name (required)

String. The string name of the popup to be shown. For the Activity Popup plugin, use "activity".

options (required)

Table. A table that specifies parameters for the popup — see the next section for details.

Options Reference

items (required)

Array. Array of individual items. See Item Array below.

excludedActivities (optional)

Array. By default, all built-in and compatible activities are shown. You can exclude an activity by specifying an array of strings where each corresponds to an activity. See Supported Activities below for valid string values.

origin (optional)

Table. Only applicable on iPad. Defines the bounds of the object (typically a button) from which the iPad's popup emerges from. A convenience pattern is to pass the contentBounds property of the object.

permittedArrowDirections (optional)

Table. Only applicable on iPad. An array of values which defines the directions in which the iPad's popup arrow may point. Valid values are "up", "down", "left", "right", or "any". The default is "any".

listener (optional)

Listener. Listener which supports basic popup events. In addition, it supports the following additional properties:

Item Array

The item array is an array of individual items, where each item is a table that contains data on which activity is to be performed. Each individual item table must contain both type and value properties.

Different activities support different item types. Please refer to Apple's documentation for a reference of supported activity types.

Type Value
"string" String value which will be converted to a NSString.
"url" String value which will be converted to a NSURL.
"image" Table in the form of { baseDir=, filename= } which specifies the image file to post. This will be converted to a UIImage.

Supported Activities

The Activity plugin supports the following activity string values, each corresponding to a built-in activity on iOS.

String Corresponding iOS Activity
"UIActivityTypePostToFacebook" UIActivityTypePostToFacebook  
"UIActivityTypePostToTwitter" UIActivityTypePostToTwitter  
"UIActivityTypePostToWeibo" UIActivityTypePostToWeibo  
"UIActivityTypeMessage" UIActivityTypeMessage  
"UIActivityTypeMail" UIActivityTypeMail  
"UIActivityTypePrint" UIActivityTypePrint  
"UIActivityTypeCopyToPasteboard" UIActivityTypeCopyToPasteboard  
"UIActivityTypeAssignToContact" UIActivityTypeAssignToContact  
"UIActivityTypeSaveToCameraRoll" UIActivityTypeSaveToCameraRoll  
"UIActivityTypeAddToReadingList" UIActivityTypeAddToReadingList  
"UIActivityTypePostToFlickr" UIActivityTypePostToFlickr  
"UIActivityTypePostToVimeo" UIActivityTypePostToVimeo  
"UIActivityTypePostToTencentWeibo" UIActivityTypePostToTencentWeibo  
"UIActivityTypeAirDrop" UIActivityTypeAirDrop  

Examples

String Items
local popupListener = {}
function popupListener:popup( event )
    print(
        "(name, type, activity, action):", 
        event.name, event.type, tostring(event.activity), tostring(event.action)
    )
end

local textItems = {
    { type = "string", value = "Hello World!" },
    { type = "string", value = "Good night, and good luck." },
}

local options = { items=textItems, listener=popupListener }

native.showPopup( "activity", options )
URL Items
local popupListener = {}
function popupListener:popup( event )
    print(
        "(name, type, activity, action):", 
        event.name, event.type, tostring(event.activity), tostring(event.action)
    )
end

local urlItems = {
    { type = "url", value = "http://www.coronalabs.com" },
    { type = "url", value = "http://docs.coronalabs.com" },
}

local options = { items=urlItems, listener=popupListener }

native.showPopup( "activity", options )
Image Items
local popupListener = {}
function popupListener:popup( event )
    print(
        "(name, type, activity, action):", 
        event.name, event.type, tostring(event.activity), tostring(event.action)
    )
end

local imageItems = {
    {
        type = "image",
        value = { filename = "world1.jpg", baseDir = system.ResourceDirectory }
    },
    {
        type = "image",
        value = { filename = "world2.jpg", baseDir = system.ResourceDirectory }
    },
}

local options = { items=imageItems, listener=popupListener }

native.showPopup( "activity", options )
Combined Items
local popupListener = {}
function popupListener:popup( event )
    print(
        "(name, type, activity, action):", 
        event.name, event.type, tostring(event.activity), tostring(event.action)
    )
end

local itemsToShare = {
    {
        type = "image",
        value = { filename = "world1.jpg", baseDir = system.ResourceDirectory }
    },
    { type = "url", value = "http://www.coronalabs.com" },
    { type = "string", value = "Hello World!" },
}

local options = { items=itemsToShare, listener=popupListener }

native.showPopup( "activity", options )