jordanbyron / react-native-quick-actions

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

action button not display on home screen or even app is open,Android(7.1) #64

Closed vishalgadhiya91 closed 6 years ago

vishalgadhiya91 commented 6 years ago

Hi,

I have implement this code in my test project in "app.js", but it will not work. Any quick option or menu can't display. I have tested in android real device (7.1) Please check my below code and respond me.

import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, Alert, DeviceEventEmitter } from 'react-native';

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

const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', });

type Props = {};

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 userInfo: { url: "https://png.icons8.com/metro/1600/email.png" // 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 App 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); Alert.alert(data.toString()); }) .catch(console.error);

DeviceEventEmitter.addListener(
  "quickActionShortcut",
  this.handleQuickAction
);

}

componentWillUnmount() { DeviceEventEmitter.removeListener( "quickActionShortcut", this.handleQuickAction ); }

handleQuickAction(data) {
this.setState({ quickAction: data });
console.log("quickActionShortcut", data);
Alert.alert("data.toString()");

}

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}>
      {instructions}
    </Text>
  </View>
);

}

// Clear them all //QuickActions.clearShortcutItems(); }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, }); `

jordanbyron commented 6 years ago

Hi @vishalgadhiya91. I'm sorry you can't get your example code to work. This tracker is for bugs with the library, not support using the library. That being said I did quickly review your example and it looks like you are using the iOS example code for icons which may be causing problems.

I suggest you review the README first and if that doesn't answer your question try posting it to a service like StackOverflow to see if someone there can help you with your project. Good luck!

vishalgadhiya91 commented 6 years ago

Thanks for replay.