-
-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(suite-native): pin matrix screen oveflow #17230
Open
PeKne
wants to merge
1
commit into
develop
Choose a base branch
from
fix/native/pin-screen-matrix-overflow
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,11 @@ | ||||||||||||||||
import { useState } from 'react'; | ||||||||||||||||
import { LayoutChangeEvent } from 'react-native'; | ||||||||||||||||
|
||||||||||||||||
import { PinFormValues, pinFormSchema } from '@suite-common/validators'; | ||||||||||||||||
import { Box, Card, HStack, Image, Loader, Text, VStack } from '@suite-native/atoms'; | ||||||||||||||||
import { Form, useForm } from '@suite-native/forms'; | ||||||||||||||||
import { Translation, TxKeyPath } from '@suite-native/intl'; | ||||||||||||||||
import { getScreenHeight } from '@trezor/env-utils'; | ||||||||||||||||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||||||||||||||||
|
||||||||||||||||
import { PinFormControlButtons } from './PinFormControlButtons'; | ||||||||||||||||
|
@@ -65,6 +69,14 @@ const loaderWrapperStyle = prepareNativeStyle(utils => ({ | |||||||||||||||
backgroundColor: utils.colors.backgroundSurfaceElevation1, | ||||||||||||||||
})); | ||||||||||||||||
|
||||||||||||||||
const imageStyle = prepareNativeStyle(() => ({ | ||||||||||||||||
flex: 1, | ||||||||||||||||
width: '100%', | ||||||||||||||||
maxHeight: 194, | ||||||||||||||||
})); | ||||||||||||||||
|
||||||||||||||||
const SCREEN_HEIGHT = getScreenHeight(); | ||||||||||||||||
|
||||||||||||||||
export const PinOnKeypad = ({ variant, onSuccess }: PinOnKeypadProps) => { | ||||||||||||||||
const { applyStyle } = useNativeStyles(); | ||||||||||||||||
const form = useForm<PinFormValues>({ | ||||||||||||||||
|
@@ -74,41 +86,67 @@ export const PinOnKeypad = ({ variant, onSuccess }: PinOnKeypadProps) => { | |||||||||||||||
}, | ||||||||||||||||
}); | ||||||||||||||||
|
||||||||||||||||
const [isImageDisplayed, setIsImageDisplayed] = useState(true); | ||||||||||||||||
|
||||||||||||||||
const translations = translationsMap[variant]; | ||||||||||||||||
|
||||||||||||||||
// Hide image if the screen is too small to fit both the image and the pin matrix. | ||||||||||||||||
const handlePinMatrixLayoutEvent = (event: LayoutChangeEvent) => { | ||||||||||||||||
if (event.nativeEvent.layout.height > 0.5 * SCREEN_HEIGHT) { | ||||||||||||||||
setIsImageDisplayed(false); | ||||||||||||||||
|
||||||||||||||||
return; | ||||||||||||||||
} | ||||||||||||||||
setIsImageDisplayed(true); | ||||||||||||||||
Comment on lines
+95
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this?
Suggested change
|
||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
<VStack spacing="sp16" alignItems="center" flex={1} marginTop="sp24"> | ||||||||||||||||
<Image source={deviceImageMap.T1B1} width={161} height={194} /> | ||||||||||||||||
<Form form={form}> | ||||||||||||||||
<VStack spacing="sp8" alignItems="center"> | ||||||||||||||||
<Text color="textSubdued"> | ||||||||||||||||
<Translation id="moduleConnectDevice.pinScreen.form.keypadInfo" /> | ||||||||||||||||
</Text> | ||||||||||||||||
<Box style={applyStyle(pinProgressWrapperStyle)}> | ||||||||||||||||
<PinFormProgress title={<Translation id={translations.formTitle} />} /> | ||||||||||||||||
</Box> | ||||||||||||||||
</VStack> | ||||||||||||||||
<Card style={applyStyle(cardStyle)}> | ||||||||||||||||
<VStack justifyContent="center" alignItems="center" spacing="sp24"> | ||||||||||||||||
{pinMatrix.map(pinRow => ( | ||||||||||||||||
<HStack key={pinRow.join('')} spacing="sp16"> | ||||||||||||||||
{pinRow.map(value => ( | ||||||||||||||||
<PinMatrixButton key={value} value={value} /> | ||||||||||||||||
))} | ||||||||||||||||
</HStack> | ||||||||||||||||
))} | ||||||||||||||||
<VStack | ||||||||||||||||
spacing="sp16" | ||||||||||||||||
alignItems="center" | ||||||||||||||||
flex={1} | ||||||||||||||||
justifyContent="flex-end" | ||||||||||||||||
marginTop="sp24" | ||||||||||||||||
> | ||||||||||||||||
{isImageDisplayed && ( | ||||||||||||||||
<Image | ||||||||||||||||
source={deviceImageMap.T1B1} | ||||||||||||||||
style={applyStyle(imageStyle)} | ||||||||||||||||
contentFit="contain" | ||||||||||||||||
/> | ||||||||||||||||
)} | ||||||||||||||||
<Box onLayout={handlePinMatrixLayoutEvent}> | ||||||||||||||||
<Form form={form}> | ||||||||||||||||
<VStack spacing="sp8" alignItems="center"> | ||||||||||||||||
<Text color="textSubdued" textAlign="center"> | ||||||||||||||||
<Translation id="moduleConnectDevice.pinScreen.form.keypadInfo" /> | ||||||||||||||||
</Text> | ||||||||||||||||
<Box style={applyStyle(pinProgressWrapperStyle)}> | ||||||||||||||||
<PinFormProgress title={<Translation id={translations.formTitle} />} /> | ||||||||||||||||
</Box> | ||||||||||||||||
</VStack> | ||||||||||||||||
<PinFormControlButtons onSuccess={onSuccess} /> | ||||||||||||||||
{form.formState.isSubmitted && ( | ||||||||||||||||
<VStack style={applyStyle(loaderWrapperStyle)} spacing="sp16"> | ||||||||||||||||
<Loader size="large" /> | ||||||||||||||||
<Text variant="titleSmall"> | ||||||||||||||||
<Translation id={translations.loaderText} /> | ||||||||||||||||
</Text> | ||||||||||||||||
<Card style={applyStyle(cardStyle)}> | ||||||||||||||||
<VStack justifyContent="center" alignItems="center" spacing="sp24"> | ||||||||||||||||
{pinMatrix.map(pinRow => ( | ||||||||||||||||
<HStack key={pinRow.join('')} spacing="sp16"> | ||||||||||||||||
{pinRow.map(value => ( | ||||||||||||||||
<PinMatrixButton key={value} value={value} /> | ||||||||||||||||
))} | ||||||||||||||||
</HStack> | ||||||||||||||||
))} | ||||||||||||||||
</VStack> | ||||||||||||||||
)} | ||||||||||||||||
</Card> | ||||||||||||||||
</Form> | ||||||||||||||||
<PinFormControlButtons onSuccess={onSuccess} /> | ||||||||||||||||
{form.formState.isSubmitted && ( | ||||||||||||||||
<VStack style={applyStyle(loaderWrapperStyle)} spacing="sp16"> | ||||||||||||||||
<Loader size="large" /> | ||||||||||||||||
<Text variant="titleSmall"> | ||||||||||||||||
<Translation id={translations.loaderText} /> | ||||||||||||||||
</Text> | ||||||||||||||||
</VStack> | ||||||||||||||||
)} | ||||||||||||||||
</Card> | ||||||||||||||||
</Form> | ||||||||||||||||
</Box> | ||||||||||||||||
</VStack> | ||||||||||||||||
); | ||||||||||||||||
}; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
💡 Verification agent
🧩 Analysis chain
Consider handling orientation changes for SCREEN_HEIGHT.
The SCREEN_HEIGHT constant is defined outside the component and won't update if orientation changes. If the app supports rotation, this could lead to incorrect display decisions.
🏁 Script executed:
Length of output: 20662
🏁 Script executed:
Length of output: 2261
Action required: Dynamically update SCREEN_HEIGHT on orientation change
The current implementation of
defines SCREEN_HEIGHT at module load time, meaning its value won’t update when the device’s orientation changes. Given that orientation events are handled elsewhere in the app (e.g., via the orientationchange listener in SuiteLayout), you should consider one of the following approaches in this component:
getScreenHeight()
inside the component’s render or a hook (such as using state with an event listener on orientation change).Dimensions.addEventListener
or equivalent) to update the screen height dynamically.Please review and adjust the implementation to ensure that the component correctly reflects display changes after rotation.