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

refactor: iOS Surface major refactoring #3738

Merged
merged 9 commits into from
Mar 20, 2023
Merged

Conversation

DimitarNestorov
Copy link
Contributor

@DimitarNestorov DimitarNestorov commented Mar 9, 2023

Summary

Fixes #3733
Fixes #3593
Closes #3681

Changes in this PR:

  • Make Surface work fine with percentage widths and heights on iOS
  • Reduced Surface from 3 Animated.Views to 2
  • Moved Surface iOS logic in a separate component
  • Memoized styles computation
  • Applying the following styles only to the outer Animated.View:
    • flex
    • width
    • height
    • opacity
    • translate
    • margins
  • To fix React Native V0.71.0 Shadow Warnings #3593 I'm applying borderRadiuses and backgroundColor to both Animated.Views

Affected components:

  • Appbar
  • BottomNavigationBar
  • Button
  • Card
  • Chip
  • AnimatedFAB
  • FAB
  • IconButton
  • Menu
  • Surface
  • Snackbar
  • Searchbar
  • Modal
  • Banner
Before After
before after

image

Test plan

Percentage width and height is applied correctly. Everything else looks as before.

@callstack-bot
Copy link

callstack-bot commented Mar 9, 2023

Hey @DimitarNestorov, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

DimitarNestorov

This comment was marked as resolved.

@github-actions
Copy link

github-actions bot commented Mar 9, 2023

The mobile version of example app from this branch is ready! You can see it here.

@DimitarNestorov DimitarNestorov marked this pull request as draft March 9, 2023 19:54
@DimitarNestorov DimitarNestorov changed the title fix: pass width and height to Surface outer layer fix: iOS Surface styles Mar 9, 2023
@DimitarNestorov DimitarNestorov force-pushed the chore/button-width branch 2 times, most recently from e3c4a2a to 485a239 Compare March 10, 2023 15:55
@DimitarNestorov DimitarNestorov changed the title fix: iOS Surface styles fix: iOS Surface major refactoring Mar 10, 2023
@DimitarNestorov DimitarNestorov changed the title fix: iOS Surface major refactoring refactor: iOS Surface major refactoring Mar 10, 2023
@DimitarNestorov DimitarNestorov marked this pull request as ready for review March 10, 2023 16:16
@lukewalczak

This comment was marked as resolved.

return (
<Animated.View
ref={ref}
style={outerLayerViewStyles}
Copy link
Member

Choose a reason for hiding this comment

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

Most likely, to get rid of the warning RCTView has a shadow set but cannot calculate shadow efficiently. I think the outer layer will need to have a backgroundColor style as well. However, it can require passing there also a borderRadius to sync it with the inner layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to work but AnimatedFAB depends on backgroundColor to be transparent. I say we still do it and open a separate issue to figure something out for AnimatedFAB.
image

Copy link
Member

Choose a reason for hiding this comment

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

This seems to work but AnimatedFAB depends on backgroundColor to be transparent. I say we still do it and open a separate issue to figure something out for AnimatedFAB.

How to reproduce it on your branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How to reproduce it on your branch?

I tried upgrading Expo but I didn't get warnings. Ended up creating an empty RN project and publishing Paper to npm: https://www.npmjs.com/package/@dimitarnestorov/react-native-paper/v/5.4.1-beta.0
Since transparent is hardcoded you need to go to node_modules/@dimitarnestorov/react-native-paper/src/components/FAB/AnimatedFAB.tsx and manually change the colour.

App.tsx:

import React from 'react';
import {
  AnimatedFAB,
} from '@dimitarnestorov/react-native-paper';

function App(): JSX.Element {
  return (
    <AnimatedFAB
      icon={'plus'}
      label={'Label'}
      extended={false}
      visible
      style={{right: 16, bottom: 16, position: 'absolute'}}
    />
  );
}

export default App;

Choose a reason for hiding this comment

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

@lukewalczak Are you all planning fixing this warning for the AnimatedFAB? This PR resolved almost all of the warnings after upgrading to 5.5.0, with the exception of the AnimatedFAB. Is there any workaround for this at the moment? I can use patch-package until there is resolution on the matter.

@DimitarNestorov

This comment was marked as resolved.

src/utils/splitStyles.ts Outdated Show resolved Hide resolved
};
}

const SurfaceIOS = forwardRef<
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a biggy but since we have MD2Surface MD3Surface SurfaceIOS and inlined logic for android and web - maybe we could extract each of them to a separate file

Comment on lines 144 to 152
const [filteredStyle, marginStyle, borderRadiusStyle] = splitStyles(
restStyle,
(style) => style.startsWith('margin'),
(style) => style.startsWith('border') && style.endsWith('Radius')
);
Copy link
Member

Choose a reason for hiding this comment

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

React Native team wants to deprecate StyleSheet.flatten so it's something we should keep in mind when writing new code and avoid such deep manipulation of styles.

react-native-community/discussions-and-proposals#496

Copy link
Member

@lukewalczak lukewalczak left a comment

Choose a reason for hiding this comment

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

Tested manually on the Android and web (on both MD generations) to confirm if there is no regression related to the previously fixed issue with different custom border radius values along with custom size - tests didn't present any problem!

Code was already reviewed by other contributors, comments were addressed.

@lukewalczak lukewalczak merged commit 352dfc9 into main Mar 20, 2023
@DimitarNestorov DimitarNestorov deleted the chore/button-width branch March 20, 2023 11:22
teneeto pushed a commit that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React Native V0.71.0 Shadow Warnings IOS - Button Width Design Bug
6 participants