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

Is it Possible with React Native #240

Closed
ElangoPrince opened this issue Mar 18, 2019 · 13 comments
Closed

Is it Possible with React Native #240

ElangoPrince opened this issue Mar 18, 2019 · 13 comments

Comments

@ElangoPrince
Copy link

ElangoPrince commented Mar 18, 2019

Dropbox login with React Native, and state any example for that?

@greg-db
Copy link
Contributor

greg-db commented Mar 18, 2019

[Cross-linking for reference: https://www.dropboxforum.com/t5/API-Support-Feedback/Dropbox-with-React-Native/m-p/334449 ]

The Dropbox Java SDK does not officially support React Native, so I can't offer support or examples for that, but I'll pass this along as a feature request.

@ElangoPrince
Copy link
Author

Okay

@ElangoPrince
Copy link
Author

ElangoPrince commented Mar 19, 2019

i'm using the Dropbox-code " android from https://www.dropbox.com/developers/chooser#android , and little customizing with react-native.

here my code:
DropboxAndroidModule.Java;

import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.WritableMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.dropbox.chooser.android.DbxChooser;

public class RNReactNativeDropboxAndroidModule extends ReactContextBaseJavaModule implements ActivityEventListener {

private final ReactApplicationContext reactContext;

private Callback pickerSuccessCallback;
private Callback pickerCancelCallback;

static final int DBX_CHOOSER_REQUEST = 0;
private DbxChooser mChooser;
private String dropboxAppId = "";
private String linkType = "";
private Boolean previewLink;

public RNReactNativeDropboxAndroidModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addActivityEventListener(this);
this.reactContext = reactContext;
}

@OverRide
public String getName() {
return "RNReactNativeDropboxAndroid";
}

@ReactMethod
public void openChooser(ReadableMap options, Callback successCallback, Callback cancelCallback) {
Activity currentActivity = getCurrentActivity();

if (currentActivity == null) {
  cancelCallback.invoke("Activity doesn't exist");
  return;
}

pickerSuccessCallback = successCallback;
pickerCancelCallback = cancelCallback;

try{
  mChooser = new DbxChooser("p0pu4fjnq9onqxz");
  mChooser.forResultType(DbxChooser.ResultType.DIRECT_LINK)
    .launch(currentActivity, DBX_CHOOSER_REQUEST);
}catch(Exception e){
  Log.v("test","nope", e);
  cancelCallback.invoke(e);
}

}

@OverRide
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (pickerSuccessCallback != null) {
if (resultCode == Activity.RESULT_CANCELED) {
pickerCancelCallback.invoke("Dropbox chooser was cancelled");
} else
if (requestCode == DBX_CHOOSER_REQUEST) {
if (resultCode == Activity.RESULT_OK) {
DbxChooser.Result result = new DbxChooser.Result(data);
WritableMap fileObj = new WritableNativeMap();
try {
fileObj.putString("name", result.getName());
fileObj.putString("link", result.getLink().toString());
fileObj.putDouble("size", result.getSize());
fileObj.putString("icon", result.getIcon().toString());
}
catch (Exception e) {
Log.d("main", "Failed to stack file info onto obj: " + e.getCause());
}

        Log.d("main", "Link to selected file: " + fileObj);
        pickerSuccessCallback.invoke(fileObj);
    } else {
        // Failed or was cancelled by the user.
        pickerCancelCallback.invoke("No data found");
    }
  }
}

}
}

DropboxAndroidPackage.Java;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RNReactNativeDropboxAndroidPackage implements ReactPackage {

@OverRide
public List createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@OverRide
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@OverRide
public List createNativeModules(ReactApplicationContext reactContext) {
List modules = new ArrayList<>();
modules.add(new RNReactNativeDropboxAndroidModule(reactContext));
return modules;
}
}

it's my ReactNative initiative method:

RNReactNativeDropboxAndroid.openChooser(
{
id: "xxxxxx",
name: "filename.txt",
link: "https://...",
bytes: 464,
},
(success)=>{
alert("Here's the file link: " + success[0].link);
},
(cancel)=>{
alert('test');
}
);

dropbox open success fully, bud can't access files, when trying to select any files from dropbox, the react app close "Unfortunately ".
any idea about this?
=> how to get call back values from dropbox.

@greg-db
Copy link
Contributor

greg-db commented Mar 19, 2019

@ElangoPrince Based on this, I see that you're actually trying to use the Dropbox Chooser for Android, which is different than the Dropbox API v2 Java SDK. I'm closing this issue accordingly, since it was opened on the SDK.

Anyway, the Android Chooser also does not officially support React Native, but I'll update the feature request accordingly.

@greg-db greg-db closed this as completed Mar 19, 2019
@ElangoPrince
Copy link
Author

@greg-db , okay thanks.

@ElangoPrince
Copy link
Author

ElangoPrince commented Jul 5, 2019

@greg-db Any update on this?

@TaylorKrusen
Copy link

TaylorKrusen commented Jul 5, 2019

Unfortunately, no updates on this feature request yet.

@iamrohitagg
Copy link

iamrohitagg commented Oct 31, 2020

Any updates on this feature?

@greg-db
Copy link
Contributor

greg-db commented Nov 2, 2020

@iamrohitagg No, I don't have any news on this feature request.

@Cannonball2134
Copy link

Any updates?

@greg-db
Copy link
Contributor

greg-db commented May 12, 2021

@Cannonball2134 No, there's no update on this request.

@Pankajjajra
Copy link

Any updates on this feature?

@greg-db
Copy link
Contributor

greg-db commented Apr 12, 2024

@Pankajjajra No, there's no plans to share on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants