Skip to content
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

[Wallet][ReDesign] QR Code / Scan screens #4017

Merged
merged 26 commits into from
Jun 9, 2020

Conversation

jeanregisser
Copy link
Contributor

@jeanregisser jeanregisser commented Jun 5, 2020

Description

This implements the QR code scan redesign.

Note:

  • The state when Camera permission is denied is not with a white background like in the design but in dark to simplify the integration with the animation.
  • Avatar used is the old one.

Other changes

  • Improve Touchable props types to accept all props from TouchableWithoutFeedback (accessibility, testID, etc)

Tested

qr-anim3


Related issues

Backwards compatibility

Yes.

@jeanregisser jeanregisser marked this pull request as ready for review June 5, 2020 13:14
@jeanregisser jeanregisser requested a review from a team June 5, 2020 13:16
@i1skn i1skn mentioned this pull request Jun 5, 2020
50 tasks
@aaronmgdr
Copy link
Member

oh wow that slide action! 🤩

const [wasFocused, setWasFocused] = useState(isFocused)
const [isPartiallyVisible, setIsPartiallyVisible] = useState(false)
const cameraPermission = useAsync(check, [
Platform.select({ ios: PERMISSIONS.IOS.CAMERA, default: PERMISSIONS.ANDROID.CAMERA }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why default? and not android?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I feel you, TypeScript complains otherwise because Platform.select return type would also contain undefined. Which is not accepted by the check function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh.

[position]
)

const animatedStyle = useMemo(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing ive been thinking about is defining big hooks like this outside the component and then just calling them.

at best its more performant (no proof) at worst it keeps the voice in my head that functions should be 10 lines or less feeling less ignored.

Copy link
Contributor Author

@jeanregisser jeanregisser Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, kinda torn with this too, I'd say it depends, sometimes it's good to have all the context in a "big" function.
Here the function is still relatively short.

@@ -9,7 +9,14 @@ import { TransactionDataInput } from 'src/send/SendAmount'
import { ReviewProps } from 'src/transactions/TransactionReview'
import { TransferConfirmationCardProps } from 'src/transactions/TransferConfirmationCard'

// tslint:disable-next-line
// Typed nested navigator params
type NestedNavigatorParams<ParamList> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bravo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Had to think carefully about this 🤯 😄

Copy link
Contributor

@jmrossy jmrossy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!! Just a few questions

packages/mobile/src/qrcode/QRGen.tsx Outdated Show resolved Hide resolved
},
(qrCode) => qrCode.data
const onBarCodeDetected = useCallback(
memoize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? Or do we create a new memoized function on each render?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah im not sure i get why its memoized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes not very obvious on the first look indeed.

It does create a new memoized version on each render, but only the first memoized version is returned, unless [scanIsForSecureSend, transactionData] change.

We could think calling memoize on each render seems heavy, but it's not very different from creating a new function in a standard useCallback call.

See https://github.com/lodash/lodash/blob/master/memoize.js#L43-L60

export default function QRScanner({ route }: Props) {
const dispatch = useDispatch()
const { t } = useTranslation(Namespaces.sendFlow7)
const inset = useSafeArea()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this would work better as an HOC instead of getting the inset and manually using it in margins like we do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I get the concern here.
I initially used SafeAreaView, but it was causing a visual glitch in the animation because of its use of onLayout.

})

const onPressClose = () => {
navigation.dangerouslyGetParent()?.goBack()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method... dangerous?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question 😄
From the docs:

Reason why the function is called dangerouslyGetParent is to warn developers against overusing it to eg. get parent of parent and other hard-to-follow patterns.

@@ -7,7 +7,7 @@ import { Screens } from 'src/navigator/Screens'

export function QRCodeIcon() {
const onQrCodePress = React.useCallback(() => {
navigate(Screens.QRScanner)
navigate(Screens.QRNavigator, { screen: Screens.QRScanner })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is screen the default screen here? If so, maybe rename it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, default screen is QRCode

}

// unstyled Touchable Text, good for making other Text Buttons such as TopBarButton
export default function BoarderlessButton(props: Props) {
const { onPress, style, children, disabled, testID } = props
const { style, children, ...rest } = props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I believe passThroughProps is a common convention for rest here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

@@ -0,0 +1,36 @@
patch-package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a github issue open on the repo with this issue? If not, should we open one? Or use a diff lib we don't have to patch?

Copy link
Contributor Author

@jeanregisser jeanregisser Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good concern, cut a few corners to avoid spending too much time on this here.
I plan to open a PR on react-native-tab-view.
The lib itself is very solid, I've used it in a bunch of past projects and a lot of effort has been put into it to provide native feeling for this.
It was created by @satya164 which is also one of the creator of of react-navigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants