jordanbyron / react-native-quick-actions

A react-native interface for Touch 3D home screen quick actions
MIT License
1.06k stars 94 forks source link

popInitialAction() is not working in iOS #47

Closed ozsirma closed 6 years ago

ozsirma commented 6 years ago

componentDidMount() { .. QuickActions.popInitialAction() .then((action) => console.log(action)) .catch(console.error); ..

DeviceEventEmitter is ok. But I could not start cold-launch app with quick actions. log is null. How can I do ?

MacKentoch commented 6 years ago

Same issue here, it is no more working on cold start with:

"react-native": "0.47.2",
"react-native-quick-actions": "^0.3.6",

project targets iOS 9 (on xcode 9)

jordanbyron commented 6 years ago

I was able to successfully test popInitialAction in iOS 11 with the latest version of the library and react-native 0.42.3. Keep in mind that for the initial action to get set the app must be launched from a cold start. That means if you are using XCode to debug the app you have to edit the scheme to "Wait for the executable to be launched" so you can start it with a quick action rather than having XCode launch it right after it's done being built. Also testing it with a log statement isn't always reliable because the debug tools take a little while to connect. I suggest updating the components state or something persistent when a quick action is set. At least for debugging purposes.

Hopefully that helps. If you are still having trouble try creating a small example project like I did and show me the code so I can help figure out what is going on. ⛹️

ozsirma commented 6 years ago

let initialQuickAction = null; if (Platform.OS === 'ios') { const QuickActions = require('react-native-quick-actions'); initialQuickAction = QuickActions.popInitialAction() .then((action) => { console.log(action); }) .catch((error) => { console.log(error); }); }

export default function startApp() { Navigation.startSingleScreenApp({ screen: { screen: 'HomeScreen', title: 'Navigation', navigatorStyle: {}, },

I use react-native-navigation. Before app starting, I added these codes. It returns null :/

"react-native": "0.44.0", "react-native-quick-actions": "^0.3.6",

jordanbyron commented 6 years ago

@ozsirma check out this section from my last comment:

Also testing it with a log statement isn't always reliable because the debug tools take a little while to connect. I suggest updating the components state or something persistent when a quick action is set. At least for debugging purposes.

ozsirma commented 6 years ago

I check your comment. But it is not working. in my app, in home page I added these codes into componentDidMount()

Can you share sample code with us ? @MacKentoch

SukhKalsi commented 6 years ago

Having the same issues as @ozsirma. We also using React Native Wix Navigation library with this library, and for cold start up it returns null.

DeviceEmitter works - but not having the cold start with QuickActions kinda prevents this from being implemented at all.

Environment: react-native: 0.47.2 react-native-quick-actions: ^0.3.6 react-native-navigation: ^1.1.80

Is it possible for this to work in tandem?

jordanbyron commented 6 years ago

Can anyone provide a simplified example showing that popInitialAction isn't working on a cold start? All of my tests show that it is working as expected.

SukhKalsi commented 6 years ago

I could get an example but it'll essentially be the same as the Wix navigation example (plus adding in this module) - @jordanbyron could you clone the example and see if the library works as expected please?

Wix example app: https://github.com/wix/react-native-navigation/tree/master/example

Thanks

jordanbyron commented 6 years ago

@SukhKalsi can you get an example only usingreact-native-quick-actions which shows that popInitialAction is not working? That's what this issue is claiming, but I haven't been able to show that in my tests.

Trouble integrating this library with another is beyond the scope of what we're trying to address here. You're probably better off asking your question in StackOverflow.

jordanbyron commented 6 years ago

Here is the example I've been working with to show that the library is working as expected. This is running "react-native": "0.42.3" and the latest version of react-native-quick-actions

import React, { Component } from "react";
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  DeviceEventEmitter
} from "react-native";

var QuickActions = require("react-native-quick-actions");

QuickActions.setShortcutItems([
  {
    type: "Orders", // Required
    title: "See your orders", // Optional, if empty, `type` will be used instead
    subtitle: "See orders you've made",
    icon: "Compose", // Pass any of UIApplicationShortcutIconType<name>
    userInfo: {
      url: "app://orders" // provide custom data, like in-app url you want to open
    }
  }
]);

QuickActions.isSupported(function(error, supported) {
  if (!supported) {
    console.log("Device does not support 3D Touch or 3D Touch is disabled.");
  }
});

export default class TestRNQA extends Component {
  constructor(props) {
    super(props);

    this.state = {};

    this.handleQuickAction = this.handleQuickAction.bind(this);
  }
  componentDidMount() {
    let self = this;
    QuickActions.popInitialAction()
      .then(function(data) {
        if (data == null) return;
        self.setState({ quickAction: data });
        console.log("popInitialAction", data);
      })
      .catch(console.error);

    DeviceEventEmitter.addListener(
      "quickActionShortcut",
      this.handleQuickAction
    );
  }
  componentWillUnmount() {
    DeviceEventEmitter.removeListener(
      "quickActionShortcut",
      this.handleQuickAction
    );
  }
  handleQuickAction(data) {
    this.setState({ quickAction: data });
    console.log("quickActionShortcut", data);
  }
  render() {
    const { quickAction } = this.state;

    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          Quick Action:
          {" "}
          {(quickAction && quickAction.type) || "None"}
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{"\n"}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}
SukhKalsi commented 6 years ago

@jordanbyron Thanks for the example code. I suppose this is a tricky one as I'm sure the example you're using works perfectly fine, however the issue @ozsirma raised does in fact relate the how its integrating with Wix nav - see code within comment https://github.com/madriska/react-native-quick-actions/issues/47#issuecomment-335087364

@ozsirma Have you managed to get this resolved at all since last time you commented on?

I wasn't looking into this last few days but will be getting back into it either today or tomorrow. I'll report back - again the issue for this is tricky as it could be related to Wix instead. However having said that, this module should work for one of the most popular React Native navigation libraries out at the moment - I suppose as the owner, its up to you whether you want to support it or not.

MacKentoch commented 6 years ago

@jordanbyron I guess/suspect in my case it was related to react-navigation.

When it worked my application still used RIP old school Navigator from RN.

Right now I just got rid of this feature. For my concern issue is closed.

jordanbyron commented 6 years ago

@SukhKalsi integration issues like this are beyond the scope of what I'm setup to handle here. A place like StackOverflow might be better suited to help you out. If there is some change that can be made to this library to better integrate with navigation libraries I'm more than happy to look at them. Of course if you do think this is a repeatable bug here please open a ticket and I'll take a look.

CRiva commented 5 years ago

Just a quick way to fix the null error experienced here for anyone else still confused:

when setting the event listener, ensure the function is null safe, like this:

import QuickActions from 'react-native-quick-actions';
import { DeviceEventEmitter } from 'react-native';

export default function handleQuickAction() {
  DeviceEventEmitter.addListener('quickActionShortcut', doSomethingWithTheAction);
}

function doSomethingWithTheAction(data) {
  if (data) {
    console.log(data.title);
    console.log(data.type);
    console.log(data.userInfo);
  }
}

it's the if (data) that makes the function only "run" when data exists.

alpamys-qanybet commented 4 years ago

@jordanbyron, I don't know how, but version 0.3.9 works but 0.3.12 not with wix navigation v1.