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

feat: add a secondary layout argument in createStyleSheet #155

Merged
merged 6 commits into from
Mar 3, 2024

Conversation

justblender
Copy link
Contributor

Summary

This PR adds a secondary layout argument for the callback function passed into createStyleSheet. This is not a breaking change for existing users who only accept one theme argument, and will only improve developer experience by providing an easier access to current breakpoint, screen orientation, dimensions, and insets without requiring users to import UnistylesRuntime every time.

Copy link

vercel bot commented Mar 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-unistyles-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 2, 2024 11:59pm

@jpudysz
Copy link
Owner

jpudysz commented Mar 2, 2024

Hey @justblender, thanks for the PR. I think injecting the second argument is a great idea. However, I'm curious, why don't we inject UnistylesRuntime itself?

By focusing solely on layout props, we might overlook additional metadata such as colorScheme, hasAdaptiveThemes, themeName, breakpoints, and other properties soon to be exposed from the native side. If this approach is intended as a shortcut, it should be equivalent to importing UnistylesRuntime.

docs/src/content/docs/reference/create-stylesheet.mdx Outdated Show resolved Hide resolved
docs/src/content/docs/reference/create-stylesheet.mdx Outdated Show resolved Hide resolved
examples/expo/src/examples/RuntimeScreen.tsx Outdated Show resolved Hide resolved
examples/expo/src/examples/RuntimeWithStyleSheetScreen.tsx Outdated Show resolved Hide resolved
src/types/unistyles.ts Outdated Show resolved Hide resolved
src/useStyles.ts Outdated Show resolved Hide resolved
src/types/stylesheet.ts Outdated Show resolved Hide resolved
src/types/breakpoints.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@justblender
Copy link
Contributor Author

Hey @jpudysz! Yeah, I might've rushed this PR a little bit 😅 Initially I wanted to pass the whole runtime too. I started reconsidering this after noticing that stylesheets are only invalidated when the stylesheet itself, theme or layout changes, so I was concerned that extra runtime properties like colorScheme might be out of sync.

const parsedStyles = useMemo(() => typeof stylesheet === 'function'
? stylesheet(theme, layout)
: stylesheet, [theme, stylesheet, layout])

But after looking again, I might've been mistaken as colorScheme change does trigger onThemeChange callback, so I guess it would work...

Copy link
Owner

@jpudysz jpudysz left a comment

Choose a reason for hiding this comment

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

Also please add yourself to the list of contributors:

@jpudysz jpudysz merged commit 3fe06d1 into jpudysz:main Mar 3, 2024
2 checks passed
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.

2 participants