Skip to content

Instantly share code, notes, and snippets.

@stevenselcuk
Created August 5, 2020 15:45
Show Gist options
  • Save stevenselcuk/7bd48c5a6fbbdcc827ce3f5ccd9f4c5d to your computer and use it in GitHub Desktop.
Save stevenselcuk/7bd48c5a6fbbdcc827ce3f5ccd9f4c5d to your computer and use it in GitHub Desktop.
Quick Actions
import React, { useEffect } from "react";
import { DeviceEventEmitter, Alert } from "react-native";
import QuickActions from "react-native-quick-actions";
import navigator from "@saypr/kanvaz-mobile-navigator";
let actionList = [
{
type: "Send", // Required
title: "Send Money", // Optional, if empty, `type` will be used instead
subtitle: "Send money from your account",
icon: "Contact", // Default ios icons or registered bundle icon See for default icons: https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/system-icons/#quick-action-icons
userInfo: {
url: "Payment", // For android we need this
},
},
{
type: "Summary", // Required
title: "See your summary", // Optional, if empty, `type` will be used instead
subtitle: "See purchases you've made",
icon: "Confirmation", // Default ios icons or registered bundle icon
userInfo: {
url: "Summary", // Provide a screen if you need
},
},
{
type: "Freeze", // Required
title: "Freeze", // Optional, if empty, `type` will be used instead
subtitle: "Freeze Your Credit Card",
icon: "Pause", // Icons instructions below
userInfo: {
url: "Account", // Provide any custom data like deep linking URL
},
},
];
const addAction = (e) => {
actionList.push(e);
};
let isQuickActionsSupported = true
QuickActions.isSupported(function(error, supported) {
if (!supported) {
isQuickActionsSupported = false
console.log('Device does not support 3D Touch or 3D Touch is disabled.');
}
});
export {isQuickActionsSupported, addAction}
const QuickActionsManager = () => {
DeviceEventEmitter.addListener("quickActionShortcut", (data) => {
console.log(data.title);
console.log(data.type);
console.log(data.userInfo);
if (data.userInfo.screen !== "") {
navigator.navigate(data.userInfo.url);
}
if (data.title === "Freeze") {
navigator.navigate(data.userInfo.url);
Alert.alert(
"Warning",
"Your card will freeze! Are you sure?",
[
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel",
},
{ text: "Yes, I am sure", onPress: () => console.log("OK Pressed") },
],
{ cancelable: true }
);
}
});
useEffect(() => {
QuickActions.setShortcutItems(actionList);
});
return null;
};
function coldLaunchManager(data) {
if (data) {
if (data.userInfo.screen !== "") {
navigator.navigate(data.userInfo.url);
}
}
}
QuickActions.popInitialAction().then(coldLaunchManager).catch(console.error);
export default QuickActionsManager;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment