-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from jpudysz/feature/static-ssr
feat: static & ssr
- Loading branch information
Showing
36 changed files
with
978 additions
and
488 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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.