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

No enum constant cl.json.RNShareModule.SHARES.sms #473

Open
rudiw opened this issue Apr 11, 2019 · 17 comments

Comments

Projects
None yet
4 participants
@rudiw
Copy link

commented Apr 11, 2019

Steps to reproduce

I just created a simple application React Native like:

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import Share from 'react-native-share';

const instructions = Platform.select({
  :
});

type Props = {};
export default class App extends Component<Props> {
  render() {

    const shareOptions = {
      title: 'Share Title',
      message: 'Message Body',
      // url: 'https://id.yahoo.com',
      social: 'sms'
    }

    console.log('App| on render method here...');
    
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
        <TouchableOpacity onPress={()=>{
          Share.shareSingle(shareOptions);
        }}>
          <View style={styles.instructions}>
            <Text>Simple Share</Text>
          </View>
        </TouchableOpacity>
      </View>
    );

  }//end of render

}//end of class

const styles = StyleSheet.create({
  container: {
    :
});

Expected behaviour

The application should show (Sharing) SMS dialog.

Actual behaviour

But, I got warning:

Possible Unhandled Promise Rejection (id: 0):
Object {
  "error": No enum constant cl.json.RNShareModule.SHARES.sms",
}

If I changed value in key social to `email', it was working by showing Gmail Application.

Environment

  • "react": "16.8.3:
  • "react-native": "0.59.3"
    -Android PIXEL_XL_API_25
    -Windows 10

react-native-share

^1.1.3:
npm -v: 6.4.1

I got error on image...

Thank you in advance..

image

@rudiw rudiw added the bug label Apr 11, 2019

@jgcmarins

This comment has been minimized.

Copy link
Collaborator

commented Apr 11, 2019

Hello @rudiw, how was the link process?
Did you linked manually?
It looks like the problem is related to it.

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 11, 2019

Hello @jgcmarins, what is the link process? I am sorry, I didn't catch your mean.
I just did:

  1. npm install react-native-share --save
  2. react-native run-android
@mikehardy

This comment has been minimized.

Copy link
Collaborator

commented Apr 11, 2019

@jgcmarins

This comment has been minimized.

Copy link
Collaborator

commented Apr 11, 2019

react-native-share has native modules which means there are native dependencies to be added to your project

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 12, 2019

@jgcmarins, so what should I do to solve the problem?

@mikehardy

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 12, 2019

@mikehardy okay, I have run command:
react-native link react-native-share
but still got the same error on image..
image

@mikehardy

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

I don't know what to tell you - the example works - try it, then very carefully apply what it does to your project 🤷‍♂

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 12, 2019

@mikehardy that's okay... I hope I can figure out by miracle way... thank you @mikehardy 👍

@jgcmarins

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

Good.
Can you try to run react-native bundle with this command: node ./node_modules/react-native/local-cli/cli.js start --reset-cache
and also delete the app from the simulator and reinstall it?
It is a good practice, after linking.

@jgcmarins

This comment has been minimized.

Copy link
Collaborator

commented Apr 12, 2019

Try to wrap your code with a try/catch statement.
Are you using Promise or async/await approach?

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 21, 2019

Hello @jgcmarins, I still got error with run command: node ./node_modules/react-native/local-cli/cli.js start --reset-cache

I just run this command:

<TouchableOpacity onPress={()=>{
          Share.shareSingle(shareOptions);
        }}>

image

@MateusAndrade

This comment has been minimized.

Copy link
Collaborator

commented Apr 21, 2019

@rudiw you can use npm start --reset-cache too. I will start a fresh project using the example you provided to see what can cause this issue.

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 21, 2019

Here the sample of project:
https://github.com/rudiw/share-simle-react-native

@MateusAndrade @jgcmarins

thank you in advance

@MateusAndrade

This comment has been minimized.

Copy link
Collaborator

commented Apr 21, 2019

@rudiw i think i found that the cause of your problem is that the version you are using dont have the SMS specific const set. Its caused because the npm version was published a time ago.

You can use the master version of this repo settinh this on your package.json:

    "react-native-share": "git+https://github.com/react-native-community/react-native-share.git"

By doing this, you can use the master version, achieving what you want. But i dont recommend doing this on a production environment, since there may be some errors.

I write a simple function to share using SMS:

  shareToSMS = async () => {
    const shareOptions = {
      title: 'Share via',
      message: 'some message',
      social: 'sms',
    };

    try {
      const shareRes = await Share.shareSingle(shareOptions);      
    } catch (error) {
      console.log('====================================');
      console.log(error);
      console.log('====================================');  
    }
  };

@jgcmarins i found that using Share.Social.SMS returns a undefined definition. This can be caused because the SMS enum wasn't set on the static of the RNShare?

  static Social = {
    FACEBOOK: NativeModules.RNShare.FACEBOOK || 'facebook',
    PAGESMANAGER: NativeModules.RNShare.PAGESMANAGER || 'pagesmanager',
    TWITTER: NativeModules.RNShare.TWITTER || 'twitter',
    WHATSAPP: NativeModules.RNShare.WHATSAPP || 'whatsapp',
    INSTAGRAM: NativeModules.RNShare.INSTAGRAM || 'instagram',
    INSTAGRAM_STORIES: NativeModules.RNShare.INSTAGRAM_STORIES || 'instagram-stories',
    GOOGLEPLUS: NativeModules.RNShare.GOOGLEPLUS || 'googleplus',
    EMAIL: NativeModules.RNShare.EMAIL || 'email',
    PINTEREST: NativeModules.RNShare.PINTEREST || 'pinterest',
  };

I can try if setting the SMS const here get rid of this problem on a PR. Because on the Android code i dont found any problem, since the SMS class is defined, etc.

@rudiw

This comment has been minimized.

Copy link
Author

commented Apr 22, 2019

@MateusAndrade
I have used the master version:
image

And I did uninstall the application before `react-native run-android', showed up new error:
image

for code like:
image

@mikehardy

This comment has been minimized.

Copy link
Collaborator

commented Apr 22, 2019

That's a totally different error. Looks to me like you simply don't have anything installed that has registered for the intent you sent. Try some super basic intent anything can handle (like pure text) just to make sure your intent sending code works, and if that works then you just need to make sure you actually have an app installed that takes the intent you want (or that your intent does what you think it does with content types etc)

@MateusAndrade MateusAndrade referenced this issue Apr 23, 2019

Merged

feature/updating example version #481

5 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.