Native file documents
Access the file system of the native device. View file documents on the device, as temporary solution until the Mendix platform supports this.
Due to the nature of this module, it comes with a disclaimer and warning, by using this module you accept and agree to it:
This module provides a convenient way for viewing files and images. However, it is an advanced, highly technical module! You need to create a custom build to use it, it does not work in the Make It Native app!
The module is free to use, as is, and we will update it regularly for new Mendix releases.
Unfortunately, we cannot provide extended support on using this module. The functions are documented and a sample project will be available too.
If you are interested we are of course willing to provide assistance, you may contact use here: https://developer.mendixcloud.com/link/partnerprofile/4808
Since you’re still reading, now comes the good stuff!
Typical usage scenario
To work with file documents on the native device
Features and limitations
Each action is documented in the module. Most have a writeToLog parameter, which controls whether the log details are written to NativeActionLog. Snippet Snippet_SyncDebug_NativeActionLog shows the log on the native app.
Just make sure to call IsNativeFileSystemAvailable at least once in your app. This is good practice anyway, it also allows your app to fail gracefully when a developer attempts to use the functionality in the Make It Native app.
Viewing file documents and images
It is possible to synchronize FileDocument entity types to the device. However, currently the viewFile JS action does not work with them because the file on the device has lost the file extension. The extension is necessary for the library to work correctly.
To come around this issue, nanoflow SUB_ViewDocument is available. It can be called with any specialization of FileDocument and will copy the file on the device to its original name and start the viewer.
Supported file types are PDF, JPG, PNG. Most Office types are supported too but on Android these open in the specific app.
Unsupported file types are treated differently on each platform: On Android nothing will happen at all on older versions, but recent Android versions throw an error when file cannot be viewed. On iOS, the viewer will open but not show any contents.
Cleanup of viewer temp files The viewFile action cannot tell if and when the viewer was closed. So there will be temporary copies on the device nanoflow SUB_DeleteFileViewerTempDirectory deletes the temporary stuff so be sure to call that flow regularly
Document picking on the device
Limitation: Some apps handle the content passed to them better than others. For example, the iOS default mail app will accept subject, body message and one or more images or documents in one shareOpen call. WhatsApp on iOS will ignore any documents as soon as texts are passed as well. Currenly the only way around this is to share any images or documents in a separate shareOpen call. Be sure to test on both platforms to check whether the result matches the requirements of your app!
- Mendix 8.18.3+
- Node modules react-native-fs, react-native-file-viewer, react-native-share and react-native-document-picker (included automatically during native build for Mx9, for Mx8 use npm install or edit package.json to add them to your build. Check the dependency json files for the right versions!
- Account.OfflineDebug boolean attribute, which controls logging. (Add this attribute to Account)
Download the Mendix appstore module.
Make sure that the NativeActionLog synchronization setting is set to 'Nothing’. (Native navigation profile, Sync configuration button)
Create a native build using the native builder UI. You need at least version 1.0.78 and allow it to update the native template if it prompts you for the update. The additional native module dependencies will be included automatically during the native build for Mx9.
Also run pod install in the ios folder again for iOS builds.
You need to add a query to the Android Manifest for Android 11 and up:<queries>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="*/*" />
Place it directly before the close tag, see screenshot.