Skip to content

Commit

Permalink
added state clear methods to bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
mzorz committed Jan 31, 2019
1 parent 8cb197f commit 6f9b05f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gutenberg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface MediaSelectedCallback {

interface MediaUploadCallback {
void onUploadMediaFileSelected(int mediaId, String mediaUri);
void onUploadMediaFileClear(int mediaId);
void onMediaFileUploadProgress(int mediaId, float progress);
void onMediaFileUploadSucceeded(int mediaId, String mediaUrl, int serverId);
void onMediaFileUploadFailed(int mediaId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final int MEDIA_UPLOAD_STATE_UPLOADING = 1;
private static final int MEDIA_UPLOAD_STATE_SUCCEEDED = 2;
private static final int MEDIA_UPLOAD_STATE_FAILED = 3;
private static final int MEDIA_UPLOAD_STATE_RESET = 4;

private static final int MEDIA_SERVER_ID_UNKNOWN = 0;

Expand Down Expand Up @@ -117,6 +118,10 @@ public void onUploadMediaFileSelected(int mediaId, String mediaUri) {
}
}

@Override public void onUploadMediaFileClear(int mediaId) {
setMediaFileUploadDataInJS(MEDIA_UPLOAD_STATE_RESET, mediaId, null, 0);
}

@Override
public void onMediaFileUploadProgress(int mediaId, float progress) {
setMediaFileUploadDataInJS(MEDIA_UPLOAD_STATE_UPLOADING, mediaId, null, progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ public void mediaFileUploadSucceeded(final int mediaId, final String mediaUrl, f
}
}

public void clearMediaFileURL(final int mediaId) {
if (isMediaUploadCallbackRegistered()) {
mPendingMediaUploadCallback.onUploadMediaFileClear(mediaId);
}
}

private boolean isMediaUploadCallbackRegistered() {
return mPendingMediaUploadCallback != null;
}
Expand Down

0 comments on commit 6f9b05f

Please sign in to comment.