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

Add new quick option(s) #361

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add new quick option(s):
- Add expo-quick-actions module
- "Add transaction" quick action
- Quick action callback for navigation
aitor-gamarra committed Jan 6, 2025
commit 9a4a6ac059d31ea1772650ee639f10ec79ac1983
11 changes: 11 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
@@ -84,6 +84,17 @@ export default {
],
},
],
[
'expo-quick-actions',
{
androidIcons: {
shortcut_add: {
foregroundImage: './src/images/icon-adaptive-add.png',
backgroundColor: '#FF5533',
},
},
},
],
],
userInterfaceStyle: 'automatic',
};
320 changes: 317 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
"expo-linking": "~6.3.1",
"expo-local-authentication": "~14.0.1",
"expo-localization": "~15.0.3",
"expo-quick-actions": "^2.0.0",
"expo-random": "~14.0.1",
"expo-secure-store": "~13.0.2",
"expo-status-bar": "~1.12.1",
Binary file added src/images/icon-adaptive-add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/es/integration/react';
import { Alert, LogBox } from 'react-native';
import { Alert, LogBox, Platform } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import * as Device from 'expo-device';
import * as QuickActions from 'expo-quick-actions';
import * as Updates from 'expo-updates';
import { loadAsync } from 'expo-font';

@@ -71,8 +72,23 @@ export default function App() {
}
};

const setQuickActions = () => {
QuickActions.setItems([
{
title: translate('transaction_screen_title'),
icon: Platform.select({
ios: 'symbol:plus.circle',
android: 'shortcut_add',
}),
id: 'create-transaction-shortcut',
params: { href: 'TransactionCreateScreen' },
},
]);
};

useEffect(() => {
(async () => {
setQuickActions();
await Promise.all([cache(), onCheckOTA()]);
})();
}, []);
15 changes: 15 additions & 0 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import {
CommonActions,
useNavigation,
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {
@@ -18,6 +19,9 @@ import {
StyleSheet, Platform, View, Pressable,
} from 'react-native';
import { useSelector } from 'react-redux';
import {
useQuickActionCallback,
} from 'expo-quick-actions/hooks';
import { RootState } from '../store';
import translate from '../i18n/locale';
import { useThemeColors } from '../lib/common';
@@ -45,6 +49,7 @@ import {
} from '../components/UI/ALibrary';
import ErrorWidget from '../components/UI/ErrorWidget';
import PrivacyScreen from '../components/UI/PrivacyScreen';
import { AbacusQuickAction } from '../types/quickAction';

const Stack = createNativeStackNavigator();
const TransactionStack = createNativeStackNavigator();
@@ -311,6 +316,15 @@ function Home() {

export default function Index() {
const { colors } = useThemeColors();
const navigationRef = useNavigationContainerRef();

useQuickActionCallback((action: AbacusQuickAction) => {
navigationRef.dispatch(
CommonActions.navigate({
name: action.params.href,
}),
);
});

return (
<NavigationContainer
@@ -321,6 +335,7 @@ export default function Index() {
background: colors.backgroundColor,
},
}}
ref={navigationRef}
>
<Stack.Navigator
initialRouteName="credentials"
7 changes: 7 additions & 0 deletions src/types/quickAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Action } from 'expo-quick-actions';

export type AbacusQuickAction = Action & {
params: {
href: string;
};
};