-
-
Notifications
You must be signed in to change notification settings - Fork 73
feat: static & ssr #463
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
Merged
Merged
feat: static & ssr #463
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1976ac0
feat: static ssr
Brentlok 9020b65
Merge branch 'main' into feature/static-ssr
Brentlok f03158b
feat: static ssr
Brentlok dad8c98
Merge branch 'main' into feature/static-ssr
Brentlok 1b838d0
Merge branch 'main' into feature/static-ssr
Brentlok 028b3c2
feat: static ssr
Brentlok 407cdf1
feat: static ssr
Brentlok 8280679
Merge branch 'main' into feature/static-ssr
Brentlok 256df2e
feat: static ssr
Brentlok b491f91
Merge branch 'main' into feature/static-ssr
Brentlok 6178892
feat: move unistyles web to singleton
Brentlok b95bd70
feat: static ssr
Brentlok cb84623
feat: static ssr
Brentlok 0f88220
feat: static ssr
Brentlok 6e3e362
feat: inject rnw styles
Brentlok f7ef8b1
feat: hydrate mq state
Brentlok 7a92b55
fix: append style tag to head
Brentlok 144ac57
chore: remove getClassName export
Brentlok 2a9ffc7
feat: static ImageBackground
Brentlok 25f2583
feat: dispose listeners when removing class
Brentlok 415cb5d
fix: static
Brentlok 0b36079
feat: imageBackground web
Brentlok b57ee88
chore: change typo in type
Brentlok 63e7410
chore: cr
Brentlok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"main": "../lib/commonjs/server/index", | ||
"module": "../lib/module/server/index", | ||
"react-native": "../src/server/index", | ||
"types": "../lib/typescript/src/server/index" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ImageBackground as NativeImageBackground } from 'react-native' | ||
import { createUnistylesImageBackground } from '../../core' | ||
|
||
export const ImageBackground = createUnistylesImageBackground(NativeImageBackground) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,56 @@ | ||
import React from 'react' | ||
import { ImageBackground as NativeImageBackground } from 'react-native' | ||
import { createUnistylesImageBackground } from '../../core' | ||
import { forwardRef } from 'react' | ||
import type { UnistylesValues } from '../../types' | ||
import { getClassName } from '../../core' | ||
import { isServer } from '../../web/utils' | ||
import { UnistylesShadowRegistry } from '../../web' | ||
|
||
export const ImageBackground = createUnistylesImageBackground(NativeImageBackground) | ||
type Props = { | ||
style?: UnistylesValues | ||
imageStyle?: UnistylesValues | ||
} | ||
|
||
export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => { | ||
let storedRef: NativeImageBackground | null = null | ||
let storedImageRef: NativeImageBackground | null = null | ||
const styleClassNames = getClassName(props.style) | ||
const imageClassNames = getClassName(props.imageStyle) | ||
|
||
return ( | ||
// @ts-expect-error - RN types are not compatible with RNW styles | ||
<NativeImageBackground | ||
{...props} | ||
style={styleClassNames} | ||
imageStyle={imageClassNames} | ||
ref={isServer() ? undefined : ref => { | ||
if (!ref) { | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash) | ||
} | ||
|
||
storedRef = ref | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.add(ref, styleClassNames?.hash) | ||
|
||
if (typeof forwardedRef === 'function') { | ||
return forwardedRef(ref) | ||
} | ||
|
||
if (forwardedRef) { | ||
forwardedRef.current = ref | ||
} | ||
}} | ||
imageRef={isServer() ? undefined : ref => { | ||
if (!ref) { | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash) | ||
} | ||
|
||
storedImageRef = ref | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.add(ref, imageClassNames?.hash) | ||
}} | ||
/> | ||
) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import { passForwardedRef } from './passForwardRef' | ||
|
||
export const createUnistylesElement = (Component: any) => React.forwardRef((props, forwardedRef) => ( | ||
<Component | ||
{...props} | ||
ref={(ref: unknown) => passForwardedRef(props, ref, forwardedRef)} | ||
/> | ||
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,39 @@ | ||
import React from 'react' | ||
import { passForwardedRef } from './passForwardRef' | ||
|
||
export const createUnistylesElement = (Component: any) => React.forwardRef((props, forwardedRef) => ( | ||
<Component | ||
{...props} | ||
ref={(ref: unknown) => passForwardedRef(props, ref, forwardedRef)} | ||
/> | ||
)) | ||
import type { UnistylesValues } from '../types' | ||
import { getClassName } from './getClassname' | ||
import { isServer } from '../web/utils' | ||
import { UnistylesShadowRegistry } from '../web' | ||
|
||
type ComponentProps = { | ||
style?: UnistylesValues | Array<UnistylesValues> | ||
} | ||
|
||
export const createUnistylesElement = (Component: any) => React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => { | ||
let storedRef: HTMLElement | null = null | ||
const classNames = getClassName(props.style) | ||
|
||
return ( | ||
<Component | ||
{...props} | ||
style={classNames} | ||
ref={isServer() ? undefined : (ref: HTMLElement | null) => { | ||
if (!ref) { | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.remove(storedRef, classNames?.hash) | ||
} | ||
|
||
storedRef = ref | ||
// @ts-expect-error hidden from TS | ||
UnistylesShadowRegistry.add(ref, classNames?.hash) | ||
|
||
if (typeof forwardedRef === 'function') { | ||
return forwardedRef(ref) | ||
} | ||
|
||
if (forwardedRef) { | ||
forwardedRef.current = ref | ||
} | ||
}} | ||
/> | ||
) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { UnistylesValues } from '../types'; | ||
import { deepMergeObjects } from '../utils'; | ||
import { UnistylesShadowRegistry } from '../web'; | ||
|
||
export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>) => { | ||
if (!unistyle) { | ||
return undefined | ||
} | ||
|
||
const style = Array.isArray(unistyle) | ||
? deepMergeObjects(...unistyle) | ||
: unistyle | ||
// @ts-expect-error hidden from TS | ||
const { hash, injectedClassName } = UnistylesShadowRegistry.addStyles(style) | ||
|
||
return hash ? { $$css: true, hash, injectedClassName } : undefined | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.