-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
various mobile onboarding fixes (#3128)
* adjustments * fix mnemonic input * fix scrolling on secret recovery phrase * cleanup and fix * fix
- Loading branch information
Showing
6 changed files
with
353 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/app-mobile/src/components/KeyboardAwareAnimatedScrollView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from "react"; | ||
import { Dimensions, TextInput, ScrollView } from "react-native"; | ||
|
||
import Animated, { | ||
useAnimatedKeyboard, | ||
useAnimatedReaction, | ||
runOnJS, | ||
KeyboardState, | ||
useAnimatedProps, | ||
useAnimatedScrollHandler, | ||
useSharedValue, | ||
useAnimatedRef, | ||
} from "react-native-reanimated"; | ||
|
||
export function withReanimatedKeyboardAwareScrollView< | ||
T extends typeof ScrollView | ||
>(Component: T) { | ||
const AnimatedScrollView = Animated.createAnimatedComponent(Component); | ||
return function KeyboardAwareReanimatedScrollView( | ||
props: React.ComponentProps<typeof ScrollView> | ||
) { | ||
const scrollY = useSharedValue(0); | ||
const keyboard = useAnimatedKeyboard(); | ||
const scrollViewRef = useAnimatedRef<ScrollView>(); | ||
|
||
const performScroll = () => { | ||
TextInput.State.currentlyFocusedInput()?.measure( | ||
(x, y, width, textInputHeight, pageX, textInputPageY) => { | ||
const textinputBottomY = textInputPageY + textInputHeight; | ||
const keyboardTopY = | ||
Dimensions.get("screen").height - keyboard.height.value; | ||
// check whether the text input is covered by the keyboard | ||
if (textinputBottomY < keyboardTopY) { | ||
return; | ||
} | ||
|
||
scrollViewRef?.current?.scrollTo({ | ||
y: scrollY.value + textinputBottomY - keyboardTopY, | ||
}); | ||
} | ||
); | ||
}; | ||
|
||
useAnimatedReaction( | ||
() => { | ||
return keyboard.state.value; | ||
}, | ||
(keyboardState) => { | ||
if (keyboardState === KeyboardState.OPEN) { | ||
runOnJS(performScroll)(); | ||
} | ||
} | ||
); | ||
|
||
const containerPaddingStyle = useAnimatedProps(() => { | ||
return { | ||
paddingBottom: keyboard.height.value, | ||
}; | ||
}); | ||
|
||
const handler = useAnimatedScrollHandler( | ||
{ | ||
onScroll: (e) => { | ||
scrollY.value = e.contentOffset.y; | ||
}, | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<AnimatedScrollView | ||
{...props} | ||
ref={scrollViewRef} | ||
scrollEventThrottle={16} | ||
onScroll={handler} | ||
> | ||
{props.children} | ||
<Animated.View style={containerPaddingStyle} /> | ||
</AnimatedScrollView> | ||
); | ||
}; | ||
} | ||
|
||
export const KeyboardAwareAnimatedScrollView = | ||
withReanimatedKeyboardAwareScrollView(ScrollView); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d4203f2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
backpack – ./
backpack-200ms.vercel.app
www.backpack.app
backpack.app
backpack-git-master-200ms.vercel.app
devnet.backpack.app