From e28dfaaa80b8402a92f9ace13639b6909b059bae Mon Sep 17 00:00:00 2001 From: mantikoros Date: Fri, 10 Jun 2022 11:35:53 -0500 Subject: [PATCH] fix ios scrolling in bet panel --- web/components/bet-panel.tsx | 6 +++++- web/lib/util/device.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 web/lib/util/device.ts diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index 109cddc2..14acaaa0 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -37,6 +37,7 @@ import { import { SellRow } from './sell-row' import { useSaveShares } from './use-save-shares' import { SignUpPrompt } from './sign-up-prompt' +import { isIOS } from 'web/lib/util/device' export function BetPanel(props: { contract: BinaryContract @@ -203,7 +204,10 @@ function BuyPanel(props: { const [inputRef, focusAmountInput] = useFocus() useEffect(() => { - if (selected) focusAmountInput() + if (selected) { + if (isIOS()) window.scrollTo(0, window.scrollY + 200) + focusAmountInput() + } }, [selected, focusAmountInput]) function onBetChoice(choice: 'YES' | 'NO') { diff --git a/web/lib/util/device.ts b/web/lib/util/device.ts new file mode 100644 index 00000000..20eabf75 --- /dev/null +++ b/web/lib/util/device.ts @@ -0,0 +1,14 @@ +export function isIOS() { + return ( + [ + 'iPad Simulator', + 'iPhone Simulator', + 'iPod Simulator', + 'iPad', + 'iPhone', + 'iPod', + ].includes(navigator.platform) || + // iPad on iOS 13 detection + (navigator.userAgent.includes('Mac') && 'ontouchend' in document) + ) +}