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

#3019 move pointerEvents style from Image to View for Avatar #3129

Merged

Conversation

dklymenk
Copy link
Contributor

@marcaaron Please check out the fix for https://github.com/Expensify/Expensify.cash/pull/3092/files#r639059422

Details

Since there is no pointerEvents style on react native Image, and we need to apply that style to a View instead, a new avatarWrapper style was created and all Avatars across the app now have a wrapping View with that style.

Fixed Issues

Fixes #3019

Tests

QA Steps

Mobile web Safari iOS:

  1. On chat page tap on user icon to go to user details
  2. Use 3D touch (long press on simulator) on the Profile icon
  3. Make sure there is no image preview pop-up as in this video:
Bug5076490_Looking_weird.mp4

Other platforms:

  1. On chat page tap on user icon to go to user details
  2. Make sure the profile icon doesn't do anything unexpected when you long press it or try to interact with it in any other way.

Try doing the same for any avatar on the app. All the avatars should be covered by this PR, not just the one mentioned on the original issue #3019

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Screen Shot 2021-05-24 at 20 56 24

Mobile Web

Simulator Screen Shot - iPhone 11 - 2021-05-24 at 20 54 23

Desktop

Screen Shot 2021-05-24 at 21 00 04

iOS

Screen Shot 2021-05-24 at 21 00 04

Android

Screen Shot 2021-05-24 at 21 00 04

@dklymenk dklymenk requested a review from a team as a code owner May 25, 2021 19:24
@MelvinBot MelvinBot requested review from Jag96 and removed request for a team May 25, 2021 19:24
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

This looks OK, but would it be easier to just add a View around the Avatar component here... ?

https://github.com/Expensify/Expensify.cash/blob/9a9099592330bc26d06408f34d76128718196eb4/src/components/Avatar.js#L30-L36

@dklymenk
Copy link
Contributor Author

@marcaaron You are right. It's definitely easier. I wasn't sure if that would be considered a good practice, to have an extra nested View just for that style, since in some places around the app, Avatar component already has a wrapping View.

If you believe I should create a view with that style inside Avatar component instead, please let me know.

There is one place where avatars are rendered, but actual Avatar component is not used in src/components/MultipleAvatars.js.

https://github.com/Expensify/Expensify.cash/blob/dc0c8b74ac04e3fd22865a3229743f0d270f7b43/src/components/MultipleAvatars.js#L48-L78

So I would need to include avatarWrapper style there somewhere anyway. Otherwise there is no real reason to do it outside Avatar component.

@marcaaron
Copy link
Contributor

I wasn't sure if that would be considered a good practice, to have an extra nested View just for that style, since in some places around the app, Avatar component already has a wrapping View.

Good point. It could make things unnecessarily heavy, but I'm not sure if there are any bad effects. If we have mostly cases of Avatars with View around them an option could be to provide something like a containerStyle prop then removing the additional View wherever another Avatar is used instead opting to replace the extra View + styles...

e.g.

<View style={[styles.someStyle]}>
    <Avatar />
</View>

would be converted to

<Avatar containerStyles={[styles.someStyle]} />

@marcaaron
Copy link
Contributor

Ultimately, I think what we want is to not have to remember to put an avatarWrapper style on every View containing an Avatar, since nobody would remember to do it.

@dklymenk
Copy link
Contributor Author

The containerStyle prop sounds very good to me.

Ultimately, I think what we want is to not have to remember to put an avatarWrapper style on every View containing an Avatar, since nobody would remember to do it.

This is a very good point.

I'll convert the PR to draft and rework it.

Thanks.

@dklymenk dklymenk marked this pull request as draft May 25, 2021 20:12
@dklymenk dklymenk marked this pull request as ready for review May 25, 2021 20:46
@dklymenk
Copy link
Contributor Author

@marcaaron

I've applied your suggestions. Named the prop containerStyle instead of containerStyles to be more in line with similar prop names across the app. Also made sure the new wrapper style is always there no matter what you pass with containerStyle.

Copy link
Contributor

@Jag96 Jag96 left a comment

Choose a reason for hiding this comment

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

Nice simplification from the original PR, just one question

src/pages/DetailsPage.js Outdated Show resolved Hide resolved
Jag96
Jag96 previously approved these changes May 26, 2021
Copy link
Contributor

@Jag96 Jag96 left a comment

Choose a reason for hiding this comment

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

LGTM, @marcaaron all yours

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Looks good to me just had one minor comment.

@@ -10,13 +10,17 @@ const propTypes = {
/** Extra styles to pass */
style: PropTypes.arrayOf(PropTypes.any),

/** Extra styles to pass to View wrapper */
containerStyle: PropTypes.arrayOf(PropTypes.any),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be containerStyles since we are accepting an array of style objects?

Also should be PropTypes.arrayOf(PropTypes.object)

Copy link
Contributor

Choose a reason for hiding this comment

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

Named the prop containerStyle instead of containerStyles to be more in line with similar prop names across the app. Also made sure the new wrapper style is always there no matter what you pass with containerStyle.

There is a guide here on the correct usage -> https://github.com/Expensify/Expensify.cash/blob/main/STYLING.md#complex-component

Probably we need to update some other incorrect usages :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are at least ten props in the app that end with style (not styles) and most of them accept any. Do I change all the ones I could find? The way I see it, it's outside the scope of the issue, especially assuming I am expected to test each change.

DeepinScreenshot_select-area_20210526211617

I'll change the naming and proptype for the new containerStyle prop and I guess the existing style prop of Avatar component too, if that's ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, please only change this specific instance.

If we see a style prop that means it can accept either an array or object. It's explained here.

Copy link
Contributor Author

@dklymenk dklymenk May 26, 2021

Choose a reason for hiding this comment

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

Ok, does it mean that proptype should be

    /** Additional styles to add after local styles */
    style: PropTypes.oneOfType([
        PropTypes.arrayOf(PropTypes.object),
        PropTypes.object,
    ]),

instead of PropTypes.arrayOf(PropTypes.any),

Copy link
Contributor

Choose a reason for hiding this comment

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

No, because this is not a style prop for a simple component, but specifically targets the wrapper element so we are looking for:

containerStyles: PropTypes.arrayOf(PropTypes.object)

Let me know if that makes sense or if the readme can be clearer about this somehow.

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, I mean the style prop, not containerStyles.

It was style: PropTypes.arrayOf(PropTypes.any), before I touched it, my question is should it be

    style: PropTypes.oneOfType([
        PropTypes.arrayOf(PropTypes.object),
        PropTypes.object,
    ]),

Since it's a simple style prop it should accept both object and array, as per styling guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed an update. The way I see it, it's either like this or we rename the style prop to something like imageStyles and allow only array of objects there. If I understand the styling guidelines correctly, this how it is meant to be if you pass 2 style props: all of them should be plural, must have names describing the target element and accept only array of objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but we should not have a combination of style and containerStyles either we have multiple elements and we are getting specific or a single element and we are being vague.

It's totally fine if you don't want to make the change. We have some clean up to do and are still figuring some things out.

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Sorry @dklymenk the pointerEvents should be on the View itself like this:

<View pointerEvents="none">

@@ -1030,6 +1028,10 @@ const styles = {
borderColor: themeColors.sidebar,
},

avatarWrapper: {
pointerEvents: 'none',
},
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe the initial guidance was wrong because pointerEvents should be a prop on the View not a style

https://reactnative.dev/docs/view#pointerevents

@dklymenk
Copy link
Contributor Author

@marcaaron
I have updated the PR with new style prop names and moved pointerEvents from style to props.

@dklymenk dklymenk requested a review from marcaaron May 27, 2021 11:30
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Awesome thanks for the changes!

@marcaaron marcaaron merged commit b4c8d11 into Expensify:main May 27, 2021
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Hold for payment 2021-06-03] mWeb - Profile - Weird behavior when using 3D touch on profile photo
4 participants