Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Change callback to events

...

  1. Use the  Ti.UI.iOS.forceTouchSupported  to test if the device supports 3D touch.
  2. Create a PreviewContext object using the  Titanium.UI.iOS.createPreviewContext() method. Pass the method a dictionary with the following properties:
    • preview: view object to use as the peeked view.
    • pop: callback function that is invoked when the peeked view is popped.
    • actions: array of PreviewActions or PreviewActionGroup objects to use as the quick actions.
    • contentHeight: height of the preview window. Defaults to fill most of the screen.
  3. Add the peek and pop events to the created preview context to receive updates about the current preview state.
  4. Attach the PreviewContext object to a view. Set the view's previewContext property to the PreviewContext object.

...

Code Block
titleapp/controllers.index.js
function popView() {
    Alloy.createController('pop').getView().open();
};
 
if (Ti.UI.iOS.forceTouchSupported) {
 
    var share = Ti.UI.iOS.createPreviewAction({
        title: "Share",
        style: Ti.UI.iOS.PREVIEW_ACTION_STYLE_DEFAULT
    });

    share.addEventListener("click", function(e) {
        // Implement share logic here
    });

    $.peekView.previewContext = Ti.UI.iOS.createPreviewContext({
        preview: Alloy.createController('preview').getView(),
        pop: popView(),
        actions: [share]
    });
 
    $.peekView.previewContext.addEventListener("peek", function() {
        Ti.API.warn("The view was peeked - Update the preview here if you want to");
    });
 
    $.peekView.previewContext.addEventListener("pop", function() {
        Ti.API.warn("The view was popped - Open the full context here");
        popView();
    });
}

Example

For a full example, see https://github.com/appcelerator-developer-relations/appc-sample-3dtouch.

...