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

chore(in-app-messaging): refactor InAppMessaging UI components to handle landscape mode #9897

Conversation

calebpollman
Copy link
Contributor

Description of changes

Improve InAppMessaging UI components device orientation handling:

  • add MessageLayout, LandscapeLayout, and PortraitLayout components
  • replace internal UI component implementations with MessageLayout
  • add getPortraitStyles and getLandscapeStyles utils in UI components for resolving orientation specific styling
  • update existing utils as needed
  • clean up some JSDoc comments to ensure correct preview information

Issue #, if available

NA

Description of how you validated changes

  • manual validation
  • updated unit tests

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

Codecov Report

Merging #9897 (274859b) into in-app-messaging/staging (7636d31) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@                    Coverage Diff                    @@
##           in-app-messaging/staging    #9897   +/-   ##
=========================================================
  Coverage                     79.27%   79.27%           
=========================================================
  Files                           327      327           
  Lines                         20633    20640    +7     
  Branches                       4518     4506   -12     
=========================================================
+ Hits                          16357    16363    +6     
- Misses                         4170     4171    +1     
  Partials                        106      106           
Impacted Files Coverage Δ
.../InAppMessaging/components/BannerMessage/styles.ts 100.00% <ø> (ø)
...ssaging/components/BannerMessage/BannerMessage.tsx 100.00% <100.00%> (ø)
...ing/components/CarouselMessage/CarouselMessage.tsx 100.00% <100.00%> (ø)
...components/CarouselMessage/CarouselMessageItem.tsx 100.00% <100.00%> (ø)
...nAppMessaging/components/CarouselMessage/styles.ts 100.00% <100.00%> (+33.33%) ⬆️
...components/FullScreenMessage/FullScreenMessage.tsx 100.00% <100.00%> (ø)
...ppMessaging/components/FullScreenMessage/styles.ts 100.00% <100.00%> (ø)
...ssaging/components/MessageLayout/MessageLayout.tsx 100.00% <100.00%> (ø)
...Messaging/components/ModalMessage/ModalMessage.tsx 100.00% <100.00%> (ø)
...c/InAppMessaging/components/ModalMessage/styles.ts 100.00% <100.00%> (ø)
... and 5 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Member

@cshfang cshfang left a comment

Choose a reason for hiding this comment

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

Just a few minor comments/questions

Copy link
Member

@cshfang cshfang left a comment

Choose a reason for hiding this comment

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

Approving since remaining feedback is just minor comment tweaks. Lgtm!

@@ -48,63 +48,87 @@ export const defaultStyle: CarouselMessageComponentStyle = StyleSheet.create({
},
});

export const getStyles = (imageDimensions: ImageStyle): CarouselMessageStyle =>
const commonStyles: Omit<CarouselMessageStyle, 'image'> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand these commonStyles are specific common styles for each of the message type but is there any benefit in having a common style across the message type? (modal, full screen, banner, carousel)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid question. At this point we could definitely just share the button and text styles across all the Message components as they do not change based on layout or orientation, but with the size of this refactor being what it is decided to leave that alone for the time being

@@ -1,4 +1,4 @@
export { default as useMessage } from './useMessage';
export { default as useMessageImage, ImageDimensions } from './useMessageImage';
export { default as useMessageProps } from './useMessageProps';
export { default as useMessageProps, UseMessageProps } from './useMessageProps';
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why are there two similar named exports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UseMessageProps is the return type of useMessageProps

@@ -30,7 +35,7 @@ export default function CarouselMessageItem(props: CarouselMessageItemProps) {

return (
<SafeAreaView style={styles.componentWrapper}>
<FullScreenContent {...props} {...messageProps} />
<MessageLayout {...props} {...messageProps} orientation={deviceOrientation} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: Where in code is the layout being set so this common element can conditionally switch to different layouts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

layout is included in props

testID={IN_APP_MESSAGING.CLOSE_BUTTON}
/>
);

return (
<View style={styles.container}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Does this generic MessageLayout component handle the differences in layouts? I remember modal having slightly different layout than fullscreen and likewise with banner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some discussion it was decided that we could closer align the component composition and would just leverage styling differences per orientation/layout

Copy link
Contributor

@Samaritan1011001 Samaritan1011001 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. Just a couple of questions out of curiosity. Thank you!

@calebpollman calebpollman merged commit 6cd8d45 into aws-amplify:in-app-messaging/staging May 13, 2022
@calebpollman calebpollman deleted the in-app-messaging/refactor-landscape-handling branch May 13, 2022 20:56
@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server amplify-help forum.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants