Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the capture attribute #2954

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathC
String[] acceptTypes = fileChooserParams.getAcceptTypes();
boolean allowMultiple = fileChooserParams.getMode() == WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE;

return this.mWebView.getThemedReactContext().getNativeModule(RNCWebViewModule.class).startPhotoPickerIntent(filePathCallback, acceptTypes, allowMultiple);
return this.mWebView.getThemedReactContext().getNativeModule(RNCWebViewModule.class).startPhotoPickerIntent(filePathCallback, acceptTypes, allowMultiple, fileChooserParams.isCaptureEnabled());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,15 @@ public void startPhotoPickerIntent(String acceptType, ValueCallback<Uri> callbac
}
}

public boolean startPhotoPickerIntent(final String[] acceptTypes, final boolean allowMultiple, ValueCallback<Uri[]> callback) {
public boolean startPhotoPickerIntent(final String[] acceptTypes, final boolean allowMultiple, final ValueCallback<Uri[]> callback, final boolean isCaptureEnabled) {
mFilePathCallback = callback;
Activity activity = mContext.getCurrentActivity();

ArrayList<Parcelable> extraIntents = new ArrayList<>();
Intent photoIntent = null;
if (!needsCameraPermission()) {
if (acceptsImages(acceptTypes)) {
Intent photoIntent = getPhotoIntent();
photoIntent = getPhotoIntent();
if (photoIntent != null) {
extraIntents.add(photoIntent);
}
Expand All @@ -282,16 +283,24 @@ public boolean startPhotoPickerIntent(final String[] acceptTypes, final boolean
}
}

Intent fileSelectionIntent = getFileChooserIntent(acceptTypes, allowMultiple);

Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, fileSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Parcelable[]{}));
if (isCaptureEnabled) {
chooserIntent = photoIntent;
} else {
Intent fileSelectionIntent = getFileChooserIntent(acceptTypes, allowMultiple);

if (chooserIntent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivityForResult(chooserIntent, PICKER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, fileSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new Parcelable[]{}));
}

if (chooserIntent != null) {
if (chooserIntent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivityForResult(chooserIntent, PICKER);
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
}
} else {
Log.w("RNCWebViewModule", "there is no Activity to handle this Intent");
Log.w("RNCWebViewModule", "there is no Camera permission");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void startPhotoPickerIntent(ValueCallback<Uri> filePathCallback, String a
mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptType, filePathCallback);
}

public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final String[] acceptTypes, final boolean allowMultiple) {
return mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptTypes, allowMultiple, callback);
public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final String[] acceptTypes, final boolean allowMultiple, final boolean isCaptureEnabled) {
return mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptTypes, allowMultiple, callback, isCaptureEnabled);
}

public void setDownloadRequest(DownloadManager.Request request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void startPhotoPickerIntent(ValueCallback<Uri> filePathCallback, String a
mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptType, filePathCallback);
}

public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final String[] acceptTypes, final boolean allowMultiple) {
return mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptTypes, allowMultiple, callback);
public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final String[] acceptTypes, final boolean allowMultiple, final boolean isCaptureEnabled) {
return mRNCWebViewModuleImpl.startPhotoPickerIntent(acceptTypes, allowMultiple, callback, isCaptureEnabled);
}

public void setDownloadRequest(DownloadManager.Request request) {
Expand Down
Loading