diff --git a/README.md b/README.md index 4131fd2..c278c77 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ class ExampleCaptureOnMountManually extends Component { } render() { return ( - + ...Something to rasterize... ); @@ -147,6 +147,7 @@ Returns a Promise of the image URI. - **`view`** is a reference to a React Native component. - **`options`** may include: + - **`fileName`** _(string)_: the file name of the file. - **`width`** / **`height`** _(number)_: the width and height of the final image (resized from the View bound. don't provide it if you want the original pixel size). - **`format`** _(string)_: either `png` or `jpg` or `webm` (Android). Defaults to `png`. - **`quality`** _(number)_: the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg) diff --git a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java index b453ee2..a43b044 100644 --- a/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java +++ b/android/src/main/java/fr/greweb/reactnativeviewshot/RNViewShotModule.java @@ -84,12 +84,13 @@ public void captureRef(int tag, ReadableMap options, Promise promise) { final Integer scaleWidth = options.hasKey("width") ? (int) (dm.density * options.getDouble("width")) : null; final Integer scaleHeight = options.hasKey("height") ? (int) (dm.density * options.getDouble("height")) : null; final String resultStreamFormat = options.getString("result"); + final String fileName = options.hasKey("fileName") ? options.getString("fileName") : null; final Boolean snapshotContentContainer = options.getBoolean("snapshotContentContainer"); try { File outputFile = null; if (Results.TEMP_FILE.equals(resultStreamFormat)) { - outputFile = createTempFile(getReactApplicationContext(), extension); + outputFile = createTempFile(getReactApplicationContext(), extension, fileName); } final Activity activity = getCurrentActivity(); @@ -163,7 +164,7 @@ private void cleanDirectory(@NonNull final File directory) { * whichever is available and has more free space. */ @NonNull - private File createTempFile(@NonNull final Context context, @NonNull final String ext) throws IOException { + private File createTempFile(@NonNull final Context context, @NonNull final String ext, String fileName) throws IOException { final File externalCacheDir = context.getExternalCacheDir(); final File internalCacheDir = context.getCacheDir(); final File cacheDir; @@ -182,6 +183,9 @@ private File createTempFile(@NonNull final Context context, @NonNull final Strin } final String suffix = "." + ext; + if (fileName != null) { + return File.createTempFile(fileName, suffix, cacheDir); + } return File.createTempFile(TEMP_FILE_PREFIX, suffix, cacheDir); } }