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

feat (android): add support to Instagram Stories video sharing #933

Conversation

kaioduarte
Copy link
Collaborator

Overview

Background video assets currently is only available for iOS, this PR aims to add support for Android as well.

Test Plan

Minimal example
import React from 'react';
import {StyleSheet, View, Button} from 'react-native';

import RNFetchBlob from 'rn-fetch-blob';
import Share from 'react-native-share';

const App = () => {
  const share = async () => {
    try {
      const cache = await RNFetchBlob.config({
        fileCache: true,
        appendExt: 'mp4',
      }).fetch('GET', 'https://www.w3schools.com/html/mov_bbb.mp4');

      await Share.shareSingle({
        social: Share.Social.INSTAGRAM_STORIES,
        method: Share.InstagramStories.SHARE_BACKGROUND_VIDEO,
        backgroundVideo: `file://${cache.path()}`,
      });
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <View style={styles.container}>
      <Button title="Share Video" onPress={share} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
});

export default App;

Example

video_2020-12-21_18-19-08.mp4

Copy link
Collaborator

@MateusAndrade MateusAndrade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @kaioduarte! 🚀 🚀 🚀

@MateusAndrade MateusAndrade merged commit 8fe628f into react-native-share:master Dec 21, 2020
@MateusAndrade
Copy link
Collaborator

🎉 This PR is included in version 4.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@EstebanFuentealba
Copy link
Collaborator

Hi, @MateusAndrade @kaioduarte I think you should not add provider logic to the generic class (ShareIntent.java). for that I should extend the class and add another social item

and override the "open" method and add that logic like

// ...
public class InstagramStoriesShare extends SingleShareIntent {
// ...
    @Override
    public void open(ReadableMap options) throws ActivityNotFoundException {
        super.open(options);
        //  extra params here
        if (ShareIntent.hasValidKey("method", options)) {
                String method = options.getString("method");
                switch (method) {
                    case "shareBackgroundVideo": {
                    // ...
                    }
                    case "shareBackgroundImage": {
                    // ...
                    }
                    case "shareStickerImage": {
                    // ...
                    }
                    case "shareBackgroundAndStickerImage": {
                    // ...
                    }
                }
        }
        this.openIntentChooser(options);
    }
}

Gracias por compartir y aportar!

Saludos!

@MateusAndrade
Copy link
Collaborator

Hi, @MateusAndrade @kaioduarte I think you should not add provider logic to the generic class (ShareIntent.java). for that I should extend the class and add another social item

and override the "open" method and add that logic like

// ...
public class InstagramStoriesShare extends SingleShareIntent {
// ...
    @Override
    public void open(ReadableMap options) throws ActivityNotFoundException {
        super.open(options);
        //  extra params here
        if (ShareIntent.hasValidKey("method", options)) {
                String method = options.getString("method");
                switch (method) {
                    case "shareBackgroundVideo": {
                    // ...
                    }
                    case "shareBackgroundImage": {
                    // ...
                    }
                    case "shareStickerImage": {
                    // ...
                    }
                    case "shareBackgroundAndStickerImage": {
                    // ...
                    }
                }
        }
        this.openIntentChooser(options);
    }
}

Gracias por compartir y aportar!

Saludos!

Nice suggestion, do you think we can go on with that @kaioduarte ?

@kaioduarte
Copy link
Collaborator Author

So we thought the same, @EstebanFuentealba!

I'm implementing FacebookStories right now and I already moved the logic to the provider. @MateusAndrade after that I can refactor the InstagramStories provider 😉.

Thanks guys.

@Lg0gs
Copy link

Lg0gs commented May 6, 2021

@kaioduarte
Which version are you using?

@kaioduarte
Copy link
Collaborator Author

@kaioduarte
Which version are you using?

Do you mean the Android version? It's 11.

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

Successfully merging this pull request may close these issues.

Can't share instagram video story on Android
4 participants