Skip to content

Commit 17ec9ae

Browse files
committed
Auto scroll to end after adding or editing addresses & amounts
1 parent f3cb17f commit 17ec9ae

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
## Unreleased (develop)
44

5+
- changed: Auto launch QR scanner for multi-out payments if previously used
6+
- changed: Auto populate amount for multi-out payments if prior amounts are similar
7+
- changed: Auto scroll to end of `SendScene2` when addresses or amounts change
8+
59
## 4.28.0 (staging)
610

711
- added: Dismissed promo cards added to `NotificationCenterScene`
812
- added: `Edge-ucation` section in `WalletDetailsScene`
913
- added: Multiple memo support to `SendScene2`
1014
- added: Add os version to the "OS" line of logs
1115
- changed: "MAX" button in `FlipInput` restyled to tertiary and moved next to the text input field
12-
- changed: Auto launch QR scanner for multi-out payments if previously used
13-
- changed: Auto populate amount for multi-out payments if prior amounts are similar
1416
- fixed: Primary button transforming on the animation on `GettingStartedScene`
1517
- fixed: `NotificationCenterScene` could crash if there was an undismissed new token notification and the associated wallet no longer existed
1618
- removed: Disable Fantom transaction list

src/__tests__/scenes/__snapshots__/SendScene2.ui.test.tsx.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ exports[`SendScene2 1 spendTarget 1`] = `
209209
extraScrollHeight={62}
210210
getScrollResponder={[Function]}
211211
handleOnScroll={[Function]}
212+
innerRef={[Function]}
212213
keyboardDismissMode="interactive"
213214
keyboardOpeningTime={250}
214215
keyboardSpace={0}
@@ -1605,6 +1606,7 @@ exports[`SendScene2 1 spendTarget with info tiles 1`] = `
16051606
extraScrollHeight={62}
16061607
getScrollResponder={[Function]}
16071608
handleOnScroll={[Function]}
1609+
innerRef={[Function]}
16081610
keyboardDismissMode="interactive"
16091611
keyboardOpeningTime={250}
16101612
keyboardSpace={0}
@@ -3229,6 +3231,7 @@ exports[`SendScene2 2 spendTargets 1`] = `
32293231
extraScrollHeight={62}
32303232
getScrollResponder={[Function]}
32313233
handleOnScroll={[Function]}
3234+
innerRef={[Function]}
32323235
keyboardDismissMode="interactive"
32333236
keyboardOpeningTime={250}
32343237
keyboardSpace={0}
@@ -4811,6 +4814,7 @@ exports[`SendScene2 2 spendTargets hide tiles 1`] = `
48114814
extraScrollHeight={62}
48124815
getScrollResponder={[Function]}
48134816
handleOnScroll={[Function]}
4817+
innerRef={[Function]}
48144818
keyboardDismissMode="interactive"
48154819
keyboardOpeningTime={250}
48164820
keyboardSpace={0}
@@ -6052,6 +6056,7 @@ exports[`SendScene2 2 spendTargets hide tiles 2`] = `
60526056
extraScrollHeight={62}
60536057
getScrollResponder={[Function]}
60546058
handleOnScroll={[Function]}
6059+
innerRef={[Function]}
60556060
keyboardDismissMode="interactive"
60566061
keyboardOpeningTime={250}
60576062
keyboardSpace={0}
@@ -7269,6 +7274,7 @@ exports[`SendScene2 2 spendTargets hide tiles 3`] = `
72697274
extraScrollHeight={62}
72707275
getScrollResponder={[Function]}
72717276
handleOnScroll={[Function]}
7277+
innerRef={[Function]}
72727278
keyboardDismissMode="interactive"
72737279
keyboardOpeningTime={250}
72747280
keyboardSpace={0}
@@ -8304,6 +8310,7 @@ exports[`SendScene2 2 spendTargets lock tiles 1`] = `
83048310
extraScrollHeight={62}
83058311
getScrollResponder={[Function]}
83068312
handleOnScroll={[Function]}
8313+
innerRef={[Function]}
83078314
keyboardDismissMode="interactive"
83088315
keyboardOpeningTime={250}
83098316
keyboardSpace={0}
@@ -9661,6 +9668,7 @@ exports[`SendScene2 2 spendTargets lock tiles 2`] = `
96619668
extraScrollHeight={62}
96629669
getScrollResponder={[Function]}
96639670
handleOnScroll={[Function]}
9671+
innerRef={[Function]}
96649672
keyboardDismissMode="interactive"
96659673
keyboardOpeningTime={250}
96669674
keyboardSpace={0}
@@ -10976,6 +10984,7 @@ exports[`SendScene2 2 spendTargets lock tiles 3`] = `
1097610984
extraScrollHeight={62}
1097710985
getScrollResponder={[Function]}
1097810986
handleOnScroll={[Function]}
10987+
innerRef={[Function]}
1097910988
keyboardDismissMode="interactive"
1098010989
keyboardOpeningTime={250}
1098110990
keyboardSpace={0}
@@ -12225,6 +12234,7 @@ exports[`SendScene2 Render SendScene 1`] = `
1222512234
extraScrollHeight={62}
1222612235
getScrollResponder={[Function]}
1222712236
handleOnScroll={[Function]}
12237+
innerRef={[Function]}
1222812238
keyboardDismissMode="interactive"
1222912239
keyboardOpeningTime={250}
1223012240
keyboardSpace={0}

src/components/scenes/SendScene2.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ import { ErrorTile } from '../tiles/ErrorTile'
6969

7070
// TODO: Check contentPadding
7171

72+
const SCROLL_TO_END_DELAY_MS = 150
73+
7274
interface Props extends EdgeAppSceneProps<'send2'> {}
7375

7476
export interface SendScene2Params {
@@ -128,7 +130,9 @@ const SendComponent = (props: Props) => {
128130
const theme = useTheme()
129131
const styles = getStyles(theme)
130132

133+
const needsScrollToEnd = React.useRef<boolean>(false)
131134
const makeSpendCounter = React.useRef<number>(0)
135+
const scrollViewRef = React.useRef<KeyboardAwareScrollView | null>(null)
132136

133137
const initialMount = React.useRef<boolean>(true)
134138
const pinInputRef = React.useRef<TextInput>(null)
@@ -269,12 +273,14 @@ const SendComponent = (props: Props) => {
269273
setMinNativeAmount(parsedUri.minNativeAmount)
270274
setExpireDate(parsedUri?.expireDate)
271275
setSpendInfo({ ...spendInfo })
276+
needsScrollToEnd.current = true
272277
}
273278
}
274279

275280
const handleAddressAmountPress = (index: number) => () => {
276281
spendInfo.spendTargets.splice(index, 1)
277282
setSpendInfo({ ...spendInfo })
283+
needsScrollToEnd.current = true
278284
}
279285

280286
const renderAddressAmountTile = (index: number, spendTarget: EdgeSpendTarget) => {
@@ -351,6 +357,7 @@ const SendComponent = (props: Props) => {
351357
setSpendInfo({ ...spendInfo })
352358
setMaxSpendSetter(-1)
353359
setFieldChanged(newField)
360+
needsScrollToEnd.current = true
354361
}
355362

356363
const handleSetMax = (index: number) => () => {
@@ -476,6 +483,7 @@ const SendComponent = (props: Props) => {
476483
const handleAddAddress = useHandler(() => {
477484
spendInfo.spendTargets.push({})
478485
setSpendInfo({ ...spendInfo })
486+
needsScrollToEnd.current = true
479487
})
480488

481489
const renderAddAddress = () => {
@@ -1133,6 +1141,19 @@ const SendComponent = (props: Props) => {
11331141
backgroundColors[0] = scaledColor
11341142
}
11351143

1144+
React.useEffect(() => {
1145+
// Hack: While you would think to use InteractionManager.runAfterInteractions,
1146+
// it doesn't work because several renders occur before the full height is
1147+
// determined and the scrollToEnd call would be effective.
1148+
const timeout = setTimeout(() => {
1149+
if (needsScrollToEnd.current) {
1150+
scrollViewRef.current?.scrollToEnd(true)
1151+
needsScrollToEnd.current = false
1152+
}
1153+
}, SCROLL_TO_END_DELAY_MS)
1154+
return () => clearTimeout(timeout)
1155+
})
1156+
11361157
return (
11371158
<SceneWrapper
11381159
hasNotifications
@@ -1146,6 +1167,10 @@ const SendComponent = (props: Props) => {
11461167
{({ insetStyle }) => (
11471168
<>
11481169
<StyledKeyboardAwareScrollView
1170+
innerRef={ref => {
1171+
const kbRef: KeyboardAwareScrollView | null = ref as any
1172+
scrollViewRef.current = kbRef
1173+
}}
11491174
contentContainerStyle={{
11501175
...insetStyle,
11511176
paddingTop: 0,

0 commit comments

Comments
 (0)