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

Add shadow inconsistency opacity fix with updated tests #1402

Merged
merged 7 commits into from
Sep 1, 2022

Conversation

lyzhan7
Copy link

@lyzhan7 lyzhan7 commented Aug 30, 2022

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Planning to make the same change upstream into RN core

Summary

Revisiting a598ee4 - this got reverted in #1385 because it introduced an issue with a test. After more investigation, it seems like the test was incorrect and the error was expected. This PR is to add back the original changes + fix an ifdef bug that was in the original change + update the test.

The issue with the test is that the react native Text component has its own props for shadows - i.e. textShadowColor, textShadowRadius, etc and the shadow props that View uses does not work on Text (i.e. shadowColor, shadowRadius, etc.). Not entirely sure how this test was passing without any errors before my change, it seems like something about the change is causing (expected) errors to actually show up.

Changelog

[macOS] [Fixed] - Shadow consistency opacity fix with test updates

Test Plan

Confirmed that on iOS and macOS, setting shadowColor/shadowOffset/etc. does not work on Text, only textShadowColor/textShadowOffset/etc works. Confirmed that after updating the tests, the tests pass.

@lyzhan7 lyzhan7 requested a review from a team as a code owner August 30, 2022 23:35
@lyzhan7
Copy link
Author

lyzhan7 commented Sep 1, 2022

Turns out textShadowOpacity does not exist (even though shadowOpacity does) - wasn't sure if this was necessary but went ahead and made sure the opacity was set to 1 in the textShadowColor. Also don't really know why it wasn't complaining before about omitting width...

@lyzhan7 lyzhan7 merged commit 19a62d9 into microsoft:main Sep 1, 2022
@lyzhan7 lyzhan7 deleted the lyzhan-shadowfix2.1 branch September 1, 2022 17:14
lyzhan7 added a commit to lyzhan7/react-native-macos that referenced this pull request Sep 1, 2022
* Redo shadow opacity consistency fix

* Update test that was introducing redboxes

* Fix yarn flow-check-ios errors

* Add comment linking to github issue

* Update comment
lyzhan7 added a commit to lyzhan7/react-native-macos that referenced this pull request Sep 1, 2022
* Redo shadow opacity consistency fix

* Update test that was introducing redboxes

* Fix yarn flow-check-ios errors

* Add comment linking to github issue

* Update comment
lyzhan7 added a commit that referenced this pull request Sep 1, 2022
#1402) (#1410)

* Redo shadow opacity consistency fix

* Update test that was introducing redboxes

* Fix yarn flow-check-ios errors

* Add comment linking to github issue

* Update comment
lyzhan7 added a commit that referenced this pull request Sep 1, 2022
#1402) (#1411)

* Redo shadow opacity consistency fix

* Update test that was introducing redboxes

* Fix yarn flow-check-ios errors

* Add comment linking to github issue

* Update comment
ghost pushed a commit to microsoft/fluentui-react-native that referenced this pull request Sep 9, 2022
### Platforms Impacted
- [x] iOS
- [x] macOS
- [ ] win32 (Office)
- [ ] windows
- [ ] android

### Description of changes

This is a follow up to investigation that happened here: microsoft/react-native-macos#1402

After fixing a bug related to shadow consistency in react-native-macOS, one of the tests in react-native-macOS started failing. The issue seemed to be with the test itself (and its still unclear why the test only started failing after the bug fix) - the test was setting shadow props (ex. shadowColor, shadowOpacity, shadowOffset, shadowRadius) on a Text element, when [Text actually has its own specific shadow props](https://reactnative.dev/docs/text-style-props#textshadowcolor) - i.e. textShadowColor, textShadowOffset, textShadowRadius (interestingly textShadowOpacity is not a thing)

I considered updating the Shadow component to also work for Text, but decided against it because Shadows on Text doesn't seem to be an actual use case - usually it's a Shadow on a View that has text on it.

This PR
- updates the jest tests that were doing the same thing as the test in react-native-macOS, the Text should be wrapped in a view and then the Shadow is wrapped around that
- updates the documentation to reflect this change

### Verification

I tried the following code that was in the Shadow jest tests in FluentTester:

```javascript
<Shadow shadowToken={theme.shadows.shadow64}>
    <Text>
        test
    </Text>
</Shadow>
```
and this actually caused a red box to appear (same error as in the react-native-macOS test that started failing)

<img width="335" alt="Screen Shot 2022-09-07 at 12 02 33 PM" src="https://user-images.githubusercontent.com/78454019/188957094-140956b4-80c0-479e-95eb-814f19d29277.png">

Changing the code to this stopped the red box from showing up.
```javascript
<Shadow shadowToken={theme.shadows.shadow64}>
    <View>
        <Text>
            test
        </Text>
    </View>
</Shadow>
```

I would have expected the jest tests to fail on any code that causes a red box, if anyone has any insight on why the jest tests did not catch this please let me know (best guess is because the red box error is coming from native code, and jest tests don't catch those).

No visible changes in the tester.

### Pull request checklist

This PR has considered (when applicable):
- [x] Automated Tests
- [x] Documentation and examples
- [ ] Keyboard Accessibility
- [ ] Voiceover
- [ ] Internationalization and Right-to-left Layouts
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Nov 16, 2022
* Redo shadow opacity consistency fix

* Update test that was introducing redboxes

* Fix yarn flow-check-ios errors

* Add comment linking to github issue

* Update comment
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.

None yet

4 participants