vxrn 1.1.536 → 1.1.538

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.
Files changed (2) hide show
  1. package/expo-plugin.cjs +80 -39
  2. package/package.json +12 -12
package/expo-plugin.cjs CHANGED
@@ -235,41 +235,64 @@ gradle.taskGraph.whenReady { taskGraph ->
235
235
 
236
236
  /**
237
237
  * Add react-native-screens Android fix to prevent crashes on Activity restarts.
238
- * This fix passes null to super.onCreate() to prevent Fragment restoration issues.
238
+ * This sets up RNScreensFragmentFactory to handle fragment restoration properly.
239
239
  *
240
240
  * On Android the View state is not persisted consistently across Activity restarts,
241
- * which can lead to crashes. By passing null to onCreate, we discard any saved
242
- * instance state that could cause Fragment restoration issues.
241
+ * which can lead to crashes. By setting the fragment factory, we ensure proper
242
+ * handling of fragment state restoration.
243
243
  *
244
244
  * This fix is required for react-native-screens and is integrated directly into vxrn
245
245
  * since we depend on react-native-screens internally.
246
246
  *
247
- * Reference: https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
247
+ * Reference: https://github.com/software-mansion/react-native-screens#android
248
248
  */
249
249
  function addReactNativeScreensFix(input) {
250
- console.info(`🔨 Ensuring react-native-screens android fix`, input)
250
+ console.info(`🔨 Ensuring react-native-screens android fix`)
251
251
 
252
252
  // Determine if this is Kotlin or Java
253
- const isKotlin = input.includes('.kt') || input.includes('class MainActivity : ReactActivity()')
253
+ const isKotlin = input.includes('class MainActivity : ReactActivity()')
254
254
 
255
- // Check if the fix is already applied
256
- if (input.includes('super.onCreate(null)')) {
257
- console.info('â„šī¸ Fragment crash fix already applied (super.onCreate(null))')
255
+ // Check if the RNScreensFragmentFactory fix is already applied
256
+ if (input.includes('RNScreensFragmentFactory')) {
257
+ console.info('â„šī¸ react-native-screens fix already applied (RNScreensFragmentFactory)')
258
258
  return input
259
259
  }
260
260
 
261
261
  if (isKotlin) {
262
- // Kotlin version - replace existing super.onCreate or add new method
263
- if (input.includes('super.onCreate(savedInstanceState)')) {
262
+ // Kotlin version
263
+ // Add necessary imports
264
+ if (!input.includes('import android.os.Bundle')) {
265
+ input = input.replace(/package\s+[\w.]+/, '$&\nimport android.os.Bundle')
266
+ }
267
+ if (
268
+ !input.includes(
269
+ 'import com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory'
270
+ )
271
+ ) {
264
272
  input = input.replace(
265
- /super\.onCreate\(savedInstanceState\)/g,
266
- `// Fragment crash fix: Pass null to onCreate to prevent Fragment restoration issues
267
- // https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
268
- super.onCreate(null)`
273
+ /package\s+[\w.]+/,
274
+ '$&\nimport com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory'
275
+ )
276
+ }
277
+
278
+ // Check if onCreate exists and update it, or add new onCreate
279
+ if (input.includes('super.onCreate(')) {
280
+ // Insert fragment factory setup before super.onCreate and ensure savedInstanceState is passed
281
+ input = input.replace(
282
+ /(override\s+fun\s+onCreate\([^)]*\)\s*\{[^}]*?)(super\.onCreate\([^)]*\))/,
283
+ (match, beforeSuper, superCall) => {
284
+ // Add fragment factory before super.onCreate
285
+ const withFactory = `${beforeSuper}// react-native-screens override
286
+ supportFragmentManager.fragmentFactory = RNScreensFragmentFactory()
287
+ `
288
+ // Ensure super.onCreate uses savedInstanceState
289
+ const fixedSuperCall = 'super.onCreate(savedInstanceState)'
290
+ return withFactory + fixedSuperCall
291
+ }
269
292
  )
270
- console.info('✅ Applied Fragment crash fix to MainActivity.kt (super.onCreate(null))')
271
- } else if (!input.includes('onCreate')) {
272
- // Need to add onCreate method for Kotlin
293
+ console.info('✅ Updated onCreate with react-native-screens fix in MainActivity.kt')
294
+ } else {
295
+ // Add new onCreate method
273
296
  const classMatch = input.match(/class\s+MainActivity\s*:\s*ReactActivity\(\)\s*\{/)
274
297
  if (classMatch) {
275
298
  const classDeclarationEnd = input.indexOf('{', classMatch.index) + 1
@@ -277,49 +300,67 @@ function addReactNativeScreensFix(input) {
277
300
  const onCreateMethod = `
278
301
 
279
302
  override fun onCreate(savedInstanceState: Bundle?) {
280
- // Fragment crash fix: Pass null to onCreate to prevent Fragment restoration issues
281
- // https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
282
- super.onCreate(null)
303
+ // react-native-screens override
304
+ supportFragmentManager.fragmentFactory = RNScreensFragmentFactory()
305
+ super.onCreate(savedInstanceState)
283
306
  }`
284
307
 
285
308
  input =
286
309
  input.slice(0, classDeclarationEnd) + onCreateMethod + input.slice(classDeclarationEnd)
287
- console.info('✅ Added onCreate with Fragment crash fix to MainActivity.kt')
310
+ console.info('✅ Added onCreate with react-native-screens fix to MainActivity.kt')
288
311
  }
289
312
  }
290
313
  } else {
291
- // Java version - replace existing super.onCreate or add new method
292
- if (input.includes('super.onCreate(savedInstanceState)')) {
314
+ // Java version
315
+ // Add necessary imports
316
+ if (!input.includes('import android.os.Bundle;')) {
317
+ input = input.replace(/package\s+[\w.]+;/, '$&\nimport android.os.Bundle;')
318
+ }
319
+ if (
320
+ !input.includes(
321
+ 'import com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory;'
322
+ )
323
+ ) {
293
324
  input = input.replace(
294
- /super\.onCreate\(savedInstanceState\)/g,
295
- `// Fragment crash fix: Pass null to onCreate to prevent Fragment restoration issues
296
- // https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
297
- super.onCreate(null)`
325
+ /package\s+[\w.]+;/,
326
+ '$&\nimport com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory;'
298
327
  )
299
- console.info('✅ Applied Fragment crash fix to MainActivity.java (super.onCreate(null))')
300
- } else if (!input.includes('onCreate')) {
301
- // Need to add onCreate method for Java
302
- // First add Bundle import if needed
303
- if (!input.includes('import android.os.Bundle;')) {
304
- input = input.replace(/package\s+[\w.]+;/, '$&\nimport android.os.Bundle;')
305
- }
328
+ }
306
329
 
330
+ // Check if onCreate exists and update it, or add new onCreate
331
+ if (input.includes('super.onCreate(')) {
332
+ // Insert fragment factory setup before super.onCreate and ensure savedInstanceState is passed
333
+ input = input.replace(
334
+ /(@Override\s*\n?\s*protected\s+void\s+onCreate\([^)]*\)\s*\{[^}]*?)(super\.onCreate\([^)]*\);?)/,
335
+ (match, beforeSuper, superCall) => {
336
+ // Add fragment factory before super.onCreate
337
+ const withFactory = `${beforeSuper}// react-native-screens override
338
+ getSupportFragmentManager().setFragmentFactory(new RNScreensFragmentFactory());
339
+ `
340
+ // Ensure super.onCreate uses savedInstanceSpace (with semicolon for Java)
341
+ const fixedSuperCall = 'super.onCreate(savedInstanceState);'
342
+ return withFactory + fixedSuperCall
343
+ }
344
+ )
345
+ console.info('✅ Updated onCreate with react-native-screens fix in MainActivity.java')
346
+ } else {
347
+ // Add new onCreate method
307
348
  const classMatch = input.match(/public\s+class\s+MainActivity\s+extends\s+ReactActivity\s*\{/)
308
349
  if (classMatch) {
309
350
  const classDeclarationEnd = input.indexOf('{', classMatch.index) + 1
310
351
 
311
352
  const onCreateMethod = `
312
353
 
354
+ // react-native-screens override
313
355
  @Override
314
356
  protected void onCreate(Bundle savedInstanceState) {
315
- // Fragment crash fix: Pass null to onCreate to prevent Fragment restoration issues
316
- // https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
317
- super.onCreate(null);
357
+ getSupportFragmentManager().setFragmentFactory(new RNScreensFragmentFactory());
358
+ super.onCreate(savedInstanceState);
318
359
  }`
319
360
 
320
361
  input =
321
362
  input.slice(0, classDeclarationEnd) + onCreateMethod + input.slice(classDeclarationEnd)
322
- console.info('✅ Added onCreate with Fragment crash fix to MainActivity.java')
363
+ console.info('✅ Added onCreate with react-native-screens fix to MainActivity.java')
323
364
  }
324
365
  }
325
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vxrn",
3
- "version": "1.1.536",
3
+ "version": "1.1.538",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -65,17 +65,17 @@
65
65
  "@hono/node-server": "^1.13.7",
66
66
  "@react-native/dev-middleware": "^0.76.5",
67
67
  "@rollup/plugin-node-resolve": "^15.2.3",
68
- "@vxrn/compiler": "1.1.536",
69
- "@vxrn/debug": "1.1.536",
70
- "@vxrn/query-string": "1.1.536",
71
- "@vxrn/react-native-prebuilt": "1.1.536",
72
- "@vxrn/resolve": "1.1.536",
73
- "@vxrn/safe-area": "1.1.536",
74
- "@vxrn/url-parse": "1.1.536",
75
- "@vxrn/utils": "1.1.536",
76
- "@vxrn/vendor": "1.1.536",
77
- "@vxrn/vite-flow": "1.1.536",
78
- "@vxrn/vite-plugin-metro": "1.1.536",
68
+ "@vxrn/compiler": "1.1.538",
69
+ "@vxrn/debug": "1.1.538",
70
+ "@vxrn/query-string": "1.1.538",
71
+ "@vxrn/react-native-prebuilt": "1.1.538",
72
+ "@vxrn/resolve": "1.1.538",
73
+ "@vxrn/safe-area": "1.1.538",
74
+ "@vxrn/url-parse": "1.1.538",
75
+ "@vxrn/utils": "1.1.538",
76
+ "@vxrn/vendor": "1.1.538",
77
+ "@vxrn/vite-flow": "1.1.538",
78
+ "@vxrn/vite-plugin-metro": "1.1.538",
79
79
  "citty": "^0.1.6",
80
80
  "dotenv": "^17.2.1",
81
81
  "dotenv-expand": "^12.0.2",