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: stateless variants #462

Merged
merged 29 commits into from
Jan 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ee7d92d
feat: redesign variants
jpudysz Dec 20, 2024
0b6b0f5
Merge branch 'main' into feature/variants
jpudysz Dec 20, 2024
8d49b77
feat: remove Variants deprecated logic
jpudysz Dec 20, 2024
d32a535
chore: allow and filter multiple expressions
jpudysz Dec 20, 2024
fcf2354
chore: add nullopt for no variants
jpudysz Dec 20, 2024
f8a137e
feat: resolve unistyle not bound
jpudysz Dec 21, 2024
b3b10c4
feat: copy variants to stylesheet
Brentlok Dec 22, 2024
90b2de8
feat: restore babel style arrays
jpudysz Dec 22, 2024
90a0b53
chore: add arguments to secrets, generate hash
jpudysz Jan 13, 2025
8ab8f15
feat: remove arrays from babel
jpudysz Jan 13, 2025
58eb4eb
feat: remove arrays from babel
jpudysz Jan 13, 2025
ca416d4
feat: allow user to specify own imports for babel plugin
jpudysz Jan 13, 2025
2e01a5a
feat: accept any styles in shadow registry
jpudysz Jan 13, 2025
738b4f3
feat: allow for passing nested array
jpudysz Jan 13, 2025
4086beb
chore: upgrade expo example
jpudysz Jan 13, 2025
d40e26d
feat: remove unistyle not bound crash, replace it with warning
jpudysz Jan 13, 2025
d492819
Merge branch 'main' into feature/variants
Brentlok Jan 14, 2025
c3ec7aa
feat: redesign web variants
Brentlok Jan 14, 2025
9f282e5
fix: add fallback getClassName for native
Brentlok Jan 14, 2025
548df50
feat: deletect dependencies withUnistyles
jpudysz Jan 14, 2025
dfa2a31
feat: pass variants to shadow registry
jpudysz Jan 14, 2025
91ced41
fix: native components unmount
Brentlok Jan 15, 2025
089b7d6
feat: align withUnistyles
jpudysz Jan 15, 2025
0ead677
feat: regression useVariants
jpudysz Jan 15, 2025
ea58b22
chore: make unistyle properties hidden on the web
Brentlok Jan 15, 2025
043fb9e
fix: unmount native elements
Brentlok Jan 15, 2025
46ba6c6
feat: regression for unistyles not bound warning
jpudysz Jan 15, 2025
19f914f
fix: improve multiple style warnings
Brentlok Jan 15, 2025
7706539
Merge branch 'feature/variants' of github.com:jpudysz/react-native-un…
Brentlok Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions cxx/core/UnistyleWrapper.h
Original file line number Diff line number Diff line change
@@ -83,14 +83,7 @@ inline static std::vector<Unistyle::Shared> unistylesFromNonExistentNativeState(
You likely altered unistyle hash key and we're not able to recover C++ state attached to this node.)");
}

if (unistyles.size() == 1) {
return unistyles;
}

throw jsi::JSError(rt, R"(Unistyles: Style is not bound!
You likely used the spread operator on a Unistyle style. If you need to merge styles use array syntax:
style={[styles.container, styles.otherProp]})");
return unistyles;
}

inline static std::vector<Unistyle::Shared> unistyleFromValue(jsi::Runtime& rt, const jsi::Value& value) {
@@ -136,7 +129,7 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
auto secrets = jsi::Object(rt);

if (arguments.has_value()) {
secrets.setProperty(rt, helpers::ARGUMENTS.c_str(), arguments.value());
helpers::defineHiddenProperty(rt, secrets, helpers::ARGUMENTS.c_str(), arguments.value());
}

obj.setProperty(rt, unistyleID, secrets);
3 changes: 3 additions & 0 deletions cxx/parser/Parser.cpp
Original file line number Diff line number Diff line change
@@ -522,6 +522,9 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
unistyleFn->seal();

// for compatibility purpose save last arguments to style instance. It will work ok, if user sees warning about multiple unistyles
helpers::defineHiddenProperty(rt, thisObject, helpers::ARGUMENTS.c_str() + std::string("_") + unistyleFn->styleKey, helpers::functionArgumentsToArray(rt, args, count));

return core::objectFromUnistyle(rt, unistylesRuntime, unistyle, variants, std::make_optional<jsi::Array>(helpers::functionArgumentsToArray(rt, args, count))).asObject(rt);
});
}
2 changes: 1 addition & 1 deletion example/App2.tsx
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ const Text: React.FunctionComponent<TextProps> = ({ value, children, size }) =>
})

return (
<RNText style={styles.text(value)}>
<RNText style={[styles.text(value), styles.bg1]}>
{children}
</RNText>
)
2 changes: 1 addition & 1 deletion src/core/warn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ViewProps } from 'react-native'

export const maybeWarnAboutMultipleUnistyles = (props: ViewProps, displayName = 'Unknown') => {
if (__DEV__ && props.style && typeof props.style === 'object') {
if (__DEV__ && props.style && !Array.isArray(props.style)) {
const unistylesKeys = Object
.keys(props.style)
.filter(key => key.startsWith('unistyles-'))