Customize file preview

The super app can customize the appearance of file previews within mini programs to ensure a consistent user interface. A file can be previewed when mini programs invoke the my.openDocument JSAPI.

Default user interface

By default, a file preview occupies the full screen and displays the file title and content. The screen only displays the document preview, with no other elements or icons. The following figure shows an example of the default UI.

image

Before you begin

To customize the user interface for action sheets, ensure that the integrated iOS IAPMiniProgram SDK is version 2.67.0 or later. For more information, see SDK release notes.

Procedure

To customize file previews, take the following steps:

Step 1: Implement GRVOpenDocumentDelegate

Define a class that implements the GRVOpenDocumentDelegate protocol. Within the class, implement the openDocument method to customize the file previews. Refer to the following code for a sample implementation. For more information about the protocol and its defined method, refer to GRVOpenDocumentDelegate.

copy
class DemoOpenDocumentImpl: NSObject, GRVOpenDocumentDelegate {
    func openDocument(with param: GRVOpenDocumentParam) {
        // Implement the logic to customize file previews.
    }
}

Step 2: Configure GRVOpenDocumentDelegate

After the SDK is initialized, create an instance of GRVExtensionDelegate and assign the implementation (for example, DemoOpenDocumentImpl in the sample) to the openDocumentDelegate property of the delegate's uiProvider. Refer to the following sample configuration code:

copy
let extensionDelegate = GRVExtensionDelegate()
extensionDelegate.uiProvider.openDocumentDelegate = DemoOpenDocumentImpl()

Protocol

GRVOpenDocumentDelegate

The GRVOpenDocumentDelegate protocol defines a method for the super app to customize file previews, which the SDK then calls to render the file preview. Refer to the following code for the protocol definition:

copy
@protocol GRVOpenDocumentDelegate <NSObject>

/// Initiate document opening operation with configuration parameters
/// - Parameters:
///   - param: Configuration parameters defining document operation settings
- (void)openDocumentWithParam:(GRVOpenDocumentParam *)param;

@end

The following table lists the details of the defined method:

Method

Required

Description

openDocumentWithParam:

Yes

Called by the SDK to render a file preview. For more information, refer to openDocumentWithParam:.

openDocumentWithParam:

The openDocumentWithParam: method has the following input parameters whose values are passed by the SDK:

Parameter

Data type

Required

Description

param

GRVOpenDocumentParam

Yes

An object that contains the configuration for a custom file preview.

GRVOpenDocumentParam

The definition of the GRVOpenDocumentParam object is as follows:

copy
@interface GRVOpenDocumentParam : NSObject

/// current View Controller
@property (nonatomic, weak) UIViewController *currentViewController;

/// Document file path URL
@property (nonatomic, copy) NSURL *fileURL;

/// File type(e.g., "pdf")
@property (nonatomic, copy) NSString *fileType;

@end

The following table lists the parameter details of this object:

Parameter

Data type

Required

Description

currentViewController

UIViewController

No

A weak reference to the view controller that displays and manages the file preview. The SDK typically passes this controller, but it might become deallocated.

fileURL

NSURL

Yes

The URL of the local file.

fileType

NSString

Yes

The type of the file.