1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Android: Fixes #11324: Fix sharing to Joplin causes back navigation to get stuck (#11355)

This commit is contained in:
Henry Heino 2024-11-09 04:54:09 -08:00 committed by GitHub
parent 0876086caa
commit a08ebb9ce5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 18 deletions

View File

@ -245,14 +245,14 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
} }
if (this.state.fromShare) { if (this.state.fromShare) {
// effectively the same as NAV_BACK but NAV_BACK causes undesired behaviour in this case: // Note: In the past, NAV_BACK caused undesired behaviour in this case:
// - share to Joplin from some other app // - share to Joplin from some other app
// - open Joplin and open any note // - open Joplin and open any note
// - go back -- with NAV_BACK this causes the app to exit rather than just showing notes // - go back -- with NAV_BACK this causes the app to exit rather than just showing notes
// This no longer seems to happen, but this case should be checked when adjusting navigation
// history behavior.
this.props.dispatch({ this.props.dispatch({
type: 'NAV_GO', type: 'NAV_BACK',
routeName: 'Notes',
folderId: this.state.note.parent_id,
}); });
ShareExtension.close(); ShareExtension.close();

View File

@ -107,6 +107,7 @@
"babel-loader": "9.1.3", "babel-loader": "9.1.3",
"babel-plugin-module-resolver": "4.1.0", "babel-plugin-module-resolver": "4.1.0",
"babel-plugin-react-native-web": "0.19.12", "babel-plugin-react-native-web": "0.19.12",
"fast-deep-equal": "3.1.3",
"fs-extra": "11.2.0", "fs-extra": "11.2.0",
"gulp": "4.0.2", "gulp": "4.0.2",
"jest": "29.7.0", "jest": "29.7.0",

View File

@ -36,6 +36,7 @@ const DropdownAlert = require('react-native-dropdownalert').default;
const AlarmServiceDriver = require('./services/AlarmServiceDriver').default; const AlarmServiceDriver = require('./services/AlarmServiceDriver').default;
const SafeAreaView = require('./components/SafeAreaView'); const SafeAreaView = require('./components/SafeAreaView');
const { connect, Provider } = require('react-redux'); const { connect, Provider } = require('react-redux');
import fastDeepEqual = require('fast-deep-equal');
import { Provider as PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper'; import { Provider as PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper';
import BackButtonService from './services/BackButtonService'; import BackButtonService from './services/BackButtonService';
import NavService from '@joplin/lib/services/NavService'; import NavService from '@joplin/lib/services/NavService';
@ -89,6 +90,8 @@ import JoplinCloudLoginScreen from './components/screens/JoplinCloudLoginScreen'
import SyncTargetNone from '@joplin/lib/SyncTargetNone'; import SyncTargetNone from '@joplin/lib/SyncTargetNone';
SyncTargetRegistry.addClass(SyncTargetNone); SyncTargetRegistry.addClass(SyncTargetNone);
SyncTargetRegistry.addClass(SyncTargetOneDrive); SyncTargetRegistry.addClass(SyncTargetOneDrive);
SyncTargetRegistry.addClass(SyncTargetNextcloud); SyncTargetRegistry.addClass(SyncTargetNextcloud);
@ -301,7 +304,18 @@ const appReducer = (state = appDefaultState, action: any) => {
const currentRoute = state.route; const currentRoute = state.route;
if (!historyGoingBack && historyCanGoBackTo(currentRoute)) { if (!historyGoingBack && historyCanGoBackTo(currentRoute)) {
navHistory.push(currentRoute); const previousRoute = navHistory.length && navHistory[navHistory.length - 1];
const isDifferentRoute = !previousRoute || !fastDeepEqual(navHistory[navHistory.length - 1], currentRoute);
// Avoid multiple consecutive duplicate screens in the navigation history -- these can make
// pressing "back" seem to have no effect.
if (isDifferentRoute) {
navHistory.push(currentRoute);
}
}
if (action.clearHistory) {
navHistory.splice(0, navHistory.length);
} }
newState = { ...state }; newState = { ...state };

View File

@ -3,6 +3,7 @@ import shim from '@joplin/lib/shim';
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import checkPermissions from './checkPermissions.js'; import checkPermissions from './checkPermissions.js';
import NavService from '@joplin/lib/services/NavService';
const { ToastAndroid } = require('react-native'); const { ToastAndroid } = require('react-native');
const { PermissionsAndroid } = require('react-native'); const { PermissionsAndroid } = require('react-native');
const { Platform } = require('react-native'); const { Platform } = require('react-native');
@ -27,27 +28,21 @@ export default async (sharedData: SharedData, folderId: string, dispatch: Functi
} }
} }
const newNote = await Note.save({
parent_id: folderId,
}, { provisional: true });
// This is a bit hacky, but the surest way to go to // This is a bit hacky, but the surest way to go to
// the needed note. We go back one screen in case there's // the needed note. We go back one screen in case there's
// already a note open - if we don't do this, the dispatch // already a note open - if we don't do this, the dispatch
// below will do nothing (because routeName wouldn't change) // below will do nothing (because routeName wouldn't change)
// Then we wait a bit for the state to be set correctly, and // Then we wait a bit for the state to be set correctly, and
// finally we go to the new note. // finally we go to the new note.
dispatch({ type: 'NAV_BACK' }); await NavService.go('Notes', { folderId, clearHistory: true });
dispatch({ type: 'SIDE_MENU_CLOSE' }); dispatch({ type: 'SIDE_MENU_CLOSE' });
const newNote = await Note.save({ shim.setTimeout(async () => {
parent_id: folderId, await NavService.go('Note', { noteId: newNote.id, sharedData });
}, { provisional: true });
shim.setTimeout(() => {
dispatch({
type: 'NAV_GO',
routeName: 'Note',
noteId: newNote.id,
sharedData: sharedData,
});
ShareExtension.close(); ShareExtension.close();
}, 5); }, 5);

View File

@ -7507,6 +7507,7 @@ __metadata:
crypto-browserify: 3.12.0 crypto-browserify: 3.12.0
deprecated-react-native-prop-types: 5.0.0 deprecated-react-native-prop-types: 5.0.0
events: 3.3.0 events: 3.3.0
fast-deep-equal: 3.1.3
fs-extra: 11.2.0 fs-extra: 11.2.0
gulp: 4.0.2 gulp: 4.0.2
jest: 29.7.0 jest: 29.7.0