Skip to content

Commit

Permalink
🐛 (mobile) fix amount input requiring two clicks on safari mobile (#4182
Browse files Browse the repository at this point in the history
)
  • Loading branch information
MatissJanis authored Jan 18, 2025
1 parent 6070166 commit 87c2604
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/desktop-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"sass": "^1.70.0",
"swc-loader": "^0.2.6",
"terser-webpack-plugin": "^5.3.10",
"ua-parser-js": "^2.0.0",
"usehooks-ts": "^3.0.1",
"uuid": "^9.0.1",
"vite": "^5.2.14",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import {
parseISO,
isValid as isValidDate,
} from 'date-fns';
import { UAParser } from 'ua-parser-js';

import { pushModal } from 'loot-core/client/actions';
import { setLastTransaction } from 'loot-core/client/queries/queriesSlice';
import { runQuery } from 'loot-core/src/client/query-helpers';
import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
import { q } from 'loot-core/src/shared/query';
import { runQuery } from 'loot-core/client/query-helpers';
import { send } from 'loot-core/platform/client/fetch';
import * as monthUtils from 'loot-core/shared/months';
import { q } from 'loot-core/shared/query';
import {
ungroupTransactions,
updateTransaction,
Expand All @@ -31,7 +32,7 @@ import {
addSplitTransaction,
deleteTransaction,
makeChild,
} from 'loot-core/src/shared/transactions';
} from 'loot-core/shared/transactions';
import {
titleFirst,
integerToCurrency,
Expand All @@ -40,7 +41,7 @@ import {
getChangedValues,
diffItems,
groupById,
} from 'loot-core/src/shared/util';
} from 'loot-core/shared/util';

import { useAccounts } from '../../../hooks/useAccounts';
import { useCategories } from '../../../hooks/useCategories';
Expand Down Expand Up @@ -69,6 +70,9 @@ import { getPrettyPayee } from '../utils';

import { FocusableAmountInput } from './FocusableAmountInput';

const agent = UAParser(navigator.userAgent);
const isIOSAgent = agent.browser.name === 'Mobile Safari';

function getFieldName(transactionId, field) {
return `${field}-${transactionId}`;
}
Expand Down Expand Up @@ -465,7 +469,11 @@ const TransactionEditInner = memo(function TransactionEditInner({

const { editingField, onRequestActiveEdit, onClearActiveEdit } =
useSingleActiveEditForm();
const [totalAmountFocused, setTotalAmountFocused] = useState(true);
const [totalAmountFocused, setTotalAmountFocused] = useState(
// iOS does not support automatically opening up the keyboard for the
// total amount field. Hence we should not focus on it on page render.
!isIOSAgent,
);
const childTransactionElementRefMap = useRef({});
const hasAccountChanged = useRef(false);

Expand All @@ -482,7 +490,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
const isInitialMount = useInitialMount();

useEffect(() => {
if (isInitialMount && isAdding) {
if (isInitialMount && isAdding && !isIOSAgent) {
onTotalAmountEdit();
}
}, [isAdding, isInitialMount, onTotalAmountEdit]);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4182.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---

Fix amount input requiring two clicks on safari mobile
35 changes: 35 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ __metadata:
sass: "npm:^1.70.0"
swc-loader: "npm:^0.2.6"
terser-webpack-plugin: "npm:^5.3.10"
ua-parser-js: "npm:^2.0.0"
usehooks-ts: "npm:^3.0.1"
uuid: "npm:^9.0.1"
vite: "npm:^5.2.14"
Expand Down Expand Up @@ -8871,6 +8872,13 @@ __metadata:
languageName: unknown
linkType: soft

"detect-europe-js@npm:^0.1.2":
version: 0.1.2
resolution: "detect-europe-js@npm:0.1.2"
checksum: 10/3d6dcf6ac451baa3050ff00e05cf1841e208bc4f27c69ec2c8df5fdf2375403cf2911f8059c9c18f258d7e176c8d308e4e0e8552500d0e30a9e95a514366ef13
languageName: node
linkType: hard

"detect-libc@npm:^2.0.0, detect-libc@npm:^2.0.1":
version: 2.0.2
resolution: "detect-libc@npm:2.0.2"
Expand Down Expand Up @@ -12300,6 +12308,13 @@ __metadata:
languageName: node
linkType: hard

"is-standalone-pwa@npm:^0.1.1":
version: 0.1.1
resolution: "is-standalone-pwa@npm:0.1.1"
checksum: 10/bbd2ee7cbea985139f66fe8785e7699f52311e9c14d74190659885222b79dd1e8845b02f69b9221a23a2b4b00e8d4bea0a5a2603b2f26cb6d2071d46093ccf84
languageName: node
linkType: hard

"is-stream@npm:^1.0.0, is-stream@npm:^1.1.0":
version: 1.1.0
resolution: "is-stream@npm:1.1.0"
Expand Down Expand Up @@ -19040,6 +19055,26 @@ __metadata:
languageName: node
linkType: hard

"ua-is-frozen@npm:^0.1.2":
version: 0.1.2
resolution: "ua-is-frozen@npm:0.1.2"
checksum: 10/0113bed77d437a3752323175f01057dd01911506225e9d33799799188a89a230ab63d2445b096d4399ea8eb94e3163608f7ac2425fb8edd0844d891490607e14
languageName: node
linkType: hard

"ua-parser-js@npm:^2.0.0":
version: 2.0.0
resolution: "ua-parser-js@npm:2.0.0"
dependencies:
detect-europe-js: "npm:^0.1.2"
is-standalone-pwa: "npm:^0.1.1"
ua-is-frozen: "npm:^0.1.2"
bin:
ua-parser-js: script/cli.js
checksum: 10/9f8f82509c5aad02d87c2a76a69c19d5a3079b8eb0156fa5a603f20db14727357922dba32647dde41b6bc3511b3e80ba563aa3093694e16dd2b8e10bd40ff8a9
languageName: node
linkType: hard

"ufo@npm:^1.3.0":
version: 1.3.2
resolution: "ufo@npm:1.3.2"
Expand Down

0 comments on commit 87c2604

Please sign in to comment.