Code Monkey home page Code Monkey logo

Comments (9)

sixmoraltales avatar sixmoraltales commented on June 10, 2024 1

Ok great. Thanks for the confirmation. I was going to try that but worried that after a successful share the state of sharedContent would no longer be null, so I would then have to also check if it changes...

from react-native-share-menu.

caiosba avatar caiosba commented on June 10, 2024
  1. I don't think it's needed... you could write that code directly in the Java module if you want: https://github.com/meedan/react-native-share-menu/blob/master/android/src/main/java/com/meedan/ShareMenuModule.java#L43. But then you would need to fork the module and it would work only for your specific case.

  2. I think you should be able to call this in any component: https://github.com/meedan/react-native-share-menu/blob/master/example/index.android.js#L25

from react-native-share-menu.

sixmoraltales avatar sixmoraltales commented on June 10, 2024

Great. Thanks for the advice.
Do you know if it's possible to bounce into the app at a particular screen in the Navigation Stack rather than at the root of the Navigation Stack?

from react-native-share-menu.

caiosba avatar caiosba commented on June 10, 2024

You should be able to do that with react-navigation, and navigate to a particular screen in the navigation stack when new shared text is received.

from react-native-share-menu.

sixmoraltales avatar sixmoraltales commented on June 10, 2024

Forgive the silly question, but I can't figure out how to use your getSharedText function to detect when there is NO shared text. The callback only fires when the function successfully finds text (or image), but if not, it returns out of the function without returning anything. Is there something I am missing about your logic? Thanks again for the help.

from react-native-share-menu.

caiosba avatar caiosba commented on June 10, 2024

I'm not sure I understand the question... how are you able to "share nothing"?

from react-native-share-menu.

sixmoraltales avatar sixmoraltales commented on June 10, 2024

Thanks a lot for the quick reply.

Apologies my question was unclear. Here's my use case:
Every time the home screen loads, I want to check for shared text in case the user is coming into the app via the Android share url button in chrome (for example). My problem is that when there is no share activity detected, ShareMenu.getSharedText immediately escapes and doesn't execute the if/else condition. Here is the code I am using in componentDidMount() ...

ShareMenu.getSharedText((text :string) => { if (text && text.length) { let comment = "empty comment" var share = { link: text, comment: comment } that.props.navigation.navigate ('AndroidShareScreen', { share: share }) } else { //if no share detected, go to login screen that.props.navigation.navigate ('LoginScreen') } }) */

I noticed this line in your ShareMenuModul.java file which means the behaviour I noticed is by design:
if(mActivity == null) { return; }

So, I'm wondering if it's possible to use your ShareMenu module to detect when there is NO share when the home screen loads (i.e. no intent, or activity)? Since getSharedText doesn't execute anything, or return anything when there is no intent detected, I can't figure out how to detect the case where there is NO shared text.

Thanks again!

from react-native-share-menu.

caiosba avatar caiosba commented on June 10, 2024

I suggest that you have the shared information in a state and populate the content there when there is shared content. When there isn't, the state will remain null and then you can go to the login screen when the state is null. Something like that below:

class Test extends Component {
  constructor(props) {
    super(props); 
    this.state = {
      sharedContent: null,
    }
  }

  componentWillMount() {
    ShareMenu.getSharedText((text :string) => {
      if (text && text.length) {
        this.setState({ sharedContent: text });
      }
    })
  }

  componentDidMount() {
    if (!this.state.sharedContent) {
      // no share detected
    }
  }
}

from react-native-share-menu.

caiosba avatar caiosba commented on June 10, 2024

Please reopen if you still have problems.

from react-native-share-menu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.