react-native-unistyles 3.0.0-nightly-20250416 → 3.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
@@ -29,7 +29,7 @@ yarn add react-native-edge-to-edge react-native-nitro-modules@0.25.2
|
|
29
29
|
| react-native-unistyles | react-native-nitro-modules |
|
30
30
|
|------------------------|----------------------------|
|
31
31
|
| 3.0.0-rc.1 | 0.25.2 |
|
32
|
-
| 3.0.0-nightly-
|
32
|
+
| 3.0.0-nightly-20250416 | 0.25.2 |
|
33
33
|
|
34
34
|
Then follow [installation guides](https://unistyl.es/v3/start/getting-started) for your platform.
|
35
35
|
|
@@ -27,7 +27,7 @@ import java.util.Locale
|
|
27
27
|
@Keep
|
28
28
|
@DoNotStrip
|
29
29
|
class NativePlatformAndroid(private val reactContext: ReactApplicationContext): HybridNativePlatformSpec(), LifecycleEventListener {
|
30
|
-
private val _insets = NativePlatformInsets(reactContext, this::getMiniRuntime) { this.
|
30
|
+
private val _insets = NativePlatformInsets(reactContext, this::getMiniRuntime) { this.onConfigChange() }
|
31
31
|
private var _miniRuntime: UnistylesNativeMiniRuntime = buildMiniRuntime()
|
32
32
|
private val _listener = NativePlatformListener(reactContext, this::getMiniRuntime) { this.diffMiniRuntime() }
|
33
33
|
|
@@ -263,6 +263,10 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
263
263
|
return changedDependencies
|
264
264
|
}
|
265
265
|
|
266
|
+
private fun onConfigChange() {
|
267
|
+
this._listener.onConfigChange()
|
268
|
+
}
|
269
|
+
|
266
270
|
override fun registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) -> Unit) {
|
267
271
|
this._listener.addPlatformListener(callback)
|
268
272
|
}
|
@@ -12,7 +12,6 @@ import androidx.core.view.WindowInsetsCompat
|
|
12
12
|
import com.facebook.proguard.annotations.DoNotStrip
|
13
13
|
import com.facebook.react.bridge.ReactApplicationContext
|
14
14
|
import com.margelo.nitro.unistyles.Insets
|
15
|
-
import com.margelo.nitro.unistyles.UnistyleDependency
|
16
15
|
import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
|
17
16
|
|
18
17
|
typealias CxxImeListener = (miniRuntime: UnistylesNativeMiniRuntime) -> Unit
|
@@ -22,7 +21,7 @@ typealias CxxImeListener = (miniRuntime: UnistylesNativeMiniRuntime) -> Unit
|
|
22
21
|
class NativePlatformInsets(
|
23
22
|
private val reactContext: ReactApplicationContext,
|
24
23
|
private val getMiniRuntime: () -> UnistylesNativeMiniRuntime,
|
25
|
-
private val
|
24
|
+
private val onConfigChange: () -> Unit
|
26
25
|
) {
|
27
26
|
private var _shouldListenToImeEvents = false
|
28
27
|
private val _imeListeners: MutableList<CxxImeListener> = mutableListOf()
|
@@ -106,7 +105,7 @@ class NativePlatformInsets(
|
|
106
105
|
return
|
107
106
|
}
|
108
107
|
|
109
|
-
|
108
|
+
this@NativePlatformInsets.onConfigChange()
|
110
109
|
|
111
110
|
if (shouldEmitImeEvent) {
|
112
111
|
this@NativePlatformInsets.emitImeEvent(this.getMiniRuntime())
|
package/package.json
CHANGED
package/plugin/index.js
CHANGED
@@ -171,6 +171,19 @@ function addUnistylesImport(path2, state) {
|
|
171
171
|
function isInsideNodeModules(state) {
|
172
172
|
return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
|
173
173
|
}
|
174
|
+
function addUnistylesRequire(path2, state) {
|
175
|
+
Object.entries(state.reactNativeImports).forEach(([componentName, uniqueName]) => {
|
176
|
+
const newRequire = t2.variableDeclaration("const", [
|
177
|
+
t2.variableDeclarator(
|
178
|
+
t2.identifier(uniqueName),
|
179
|
+
t2.callExpression(t2.identifier("require"), [
|
180
|
+
t2.stringLiteral(`react-native-unistyles/src/components/native/${componentName}`)
|
181
|
+
])
|
182
|
+
)
|
183
|
+
]);
|
184
|
+
path2.node.body.unshift(newRequire);
|
185
|
+
});
|
186
|
+
}
|
174
187
|
|
175
188
|
// plugin/src/ref.ts
|
176
189
|
var t3 = __toESM(require("@babel/types"));
|
@@ -314,10 +327,29 @@ function stringToUniqueId(str) {
|
|
314
327
|
}
|
315
328
|
function isUnistylesStyleSheet(path2, state) {
|
316
329
|
const { callee } = path2.node;
|
317
|
-
if (t4.isMemberExpression(callee)
|
318
|
-
return
|
330
|
+
if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
|
331
|
+
return false;
|
332
|
+
}
|
333
|
+
const isImport = callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
|
334
|
+
const isRequire = state.file.hasUnistylesImport && callee.property.name === "create" && t4.isMemberExpression(callee.object) && t4.isIdentifier(callee.object.property) && t4.isIdentifier(callee.object.object) && callee.object.object.name === state.file.styleSheetLocalName && callee.object.property.name === "StyleSheet";
|
335
|
+
return isImport || isRequire;
|
336
|
+
}
|
337
|
+
function isUnistylesCommonJSRequire(path2, state) {
|
338
|
+
const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && t4.isStringLiteral(path2.node.arguments[0]) && path2.node.arguments[0].value === "react-native-unistyles";
|
339
|
+
if (isRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
|
340
|
+
state.file.hasUnistylesImport = true;
|
341
|
+
state.file.styleSheetLocalName = path2.parent.id.name;
|
319
342
|
}
|
320
|
-
return
|
343
|
+
return isRequire;
|
344
|
+
}
|
345
|
+
function isReactNativeCommonJSRequire(path2, state) {
|
346
|
+
const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && path2.node.callee.name === "require";
|
347
|
+
const requireImportName = path2.node.arguments.find((node) => t4.isStringLiteral(node));
|
348
|
+
const isReactNativeRequire = isRequire && requireImportName && (requireImportName.value === "react-native" || requireImportName.value === "react-native-web/dist/index");
|
349
|
+
if (isReactNativeRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
|
350
|
+
state.file.reactNativeCommonJSName = path2.parent.id.name;
|
351
|
+
}
|
352
|
+
return isRequire;
|
321
353
|
}
|
322
354
|
function isKindOfStyleSheet(path2, state) {
|
323
355
|
if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
|
@@ -691,8 +723,10 @@ function index_default() {
|
|
691
723
|
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
|
692
724
|
state.file.hasAnyUnistyle = false;
|
693
725
|
state.file.hasUnistylesImport = false;
|
726
|
+
state.file.addUnistylesRequire = false;
|
694
727
|
state.file.hasVariants = false;
|
695
728
|
state.file.styleSheetLocalName = "";
|
729
|
+
state.file.reactNativeCommonJSName = "";
|
696
730
|
state.file.tagNumber = 0;
|
697
731
|
state.reactNativeImports = {};
|
698
732
|
state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
|
@@ -709,6 +743,9 @@ function index_default() {
|
|
709
743
|
if (isInsideNodeModules(state)) {
|
710
744
|
return;
|
711
745
|
}
|
746
|
+
if (state.file.addUnistylesRequire) {
|
747
|
+
return addUnistylesRequire(path2, state);
|
748
|
+
}
|
712
749
|
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
713
750
|
addUnistylesImport(path2, state);
|
714
751
|
}
|
@@ -784,10 +821,33 @@ function index_default() {
|
|
784
821
|
throw new Error("Detected string based ref which is not supported by Unistyles.");
|
785
822
|
}
|
786
823
|
},
|
824
|
+
MemberExpression(path2, state) {
|
825
|
+
if (isInsideNodeModules(state)) {
|
826
|
+
return;
|
827
|
+
}
|
828
|
+
if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {
|
829
|
+
return;
|
830
|
+
}
|
831
|
+
if (path2.node.object.name !== state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.property)) {
|
832
|
+
return;
|
833
|
+
}
|
834
|
+
if (!state.reactNativeImports[path2.node.property.name]) {
|
835
|
+
const uniqueId = path2.scope.generateUidIdentifier(`reactNativeUnistyles_${path2.node.property.name}`);
|
836
|
+
state.reactNativeImports[path2.node.property.name] = uniqueId.name;
|
837
|
+
state.file.addUnistylesRequire = true;
|
838
|
+
}
|
839
|
+
path2.node.object.name = state.reactNativeImports[path2.node.property.name];
|
840
|
+
},
|
787
841
|
CallExpression(path2, state) {
|
788
842
|
if (isInsideNodeModules(state)) {
|
789
843
|
return;
|
790
844
|
}
|
845
|
+
if (isUnistylesCommonJSRequire(path2, state)) {
|
846
|
+
return;
|
847
|
+
}
|
848
|
+
if (isReactNativeCommonJSRequire(path2, state)) {
|
849
|
+
return;
|
850
|
+
}
|
791
851
|
if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
|
792
852
|
return;
|
793
853
|
}
|