alinz / react-native-share-extension

react-native as an engine to drive share extension
MIT License
765 stars 401 forks source link

Opening video file freezes application #61

Open asleepace opened 7 years ago

asleepace commented 7 years ago

Environment react-native: 0.45.1 release version android: 7.0 ios: 11.1

Hi the ShareExtension has been working great for images, text & links, but seems to crash my application when opening a video. This happens on both iOS and Android, and it seems to stall on this line:

const { type, value } = await ShareExtension.data();

Any help would be greatly appreciated thanks!

alinz commented 7 years ago

@Asleepace, Don't use the data method to grab the data for video, instead get the path of the video. And also share extension meant to be use to do one thing and one simple tasks. If you need to do more complex operation, you should prompt the user to go back to your main app and load the content there for further processing.

asleepace commented 7 years ago

@alinz awesome, thanks I will try that out! Also is there any way to determine the type before hand so I can either use the video url or get the data?

asleepace commented 7 years ago

@alinz hey I forked the repo and have it working for iOS, I'll submit a PR once we get it working for Android too.

vbashiri commented 5 years ago

My problem is slightly different, but the outcome is the same. There problem is when I click on share button in safari or anywhere else the app will freeze, but when I change background of view in MainInterface.storyboard to solid black, the view will be rendered. A black page will be appeared and because of that touches not working and it looks like the app is frozen. So, view will rendered but the react native will not start. Where I go wrong and how I fix it.

OmarBasem commented 5 years ago

@Asleepace @vbashiri Did anybody find a solution please?

asleepace commented 5 years ago

@ramon90 yes in the ShareModule.java I modified the processIntent() method to the following:

    public WritableMap processIntent() {
        WritableMap map = Arguments.createMap();

        List<String> values = new ArrayList<>();
        String type = "";
        String action = "";

        Activity currentActivity = getCurrentActivity();

        if (currentActivity != null) {
            Intent intent = currentActivity.getIntent();
            action = intent.getAction();
            type = intent.getType();
            if (type == null) {
                type = "";
            }
            if (Intent.ACTION_SEND.equals(action) && !type.equals("")) {
                if ("text/plain".equals(type)) {
                    values.add(handleSendText(intent)); // Handle text being sent
                } else {
                    values.add(handleSendFile(intent)); // Handle single file being sent
                }
            } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && !type.equals("")) {
                values.addAll(handleSendMultipleFiles(intent)); // Handle single image being sent

            } else {
                // not ACTION_SEND or ACTION_SEND_MULTIPLE (will not happen)
                // do nothing
            }
        } else {
            // null activity
            // do nothing
        }

        WritableArray files = Arguments.createArray();
        for (String value : values) {
            WritableMap file = Arguments.createMap();
            file.putString("type", type);
            file.putString("value", value);
            files.pushMap(file);
        }
        map.putArray("files", files);

        return map;
    }