peachsim 0.1.659 → 0.1.660

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 (86) hide show
  1. package/cli/cli-update.ts +53 -21
  2. package/cli/commands/compat.ts +6 -2
  3. package/cli/commands/control.ts +12 -3
  4. package/cli/commands/inspect.ts +16 -14
  5. package/cli/commands/upgrade.ts +4 -2
  6. package/cli/current-sim.ts +4 -0
  7. package/dist-lib/agent-daemon-client.cjs +1 -1
  8. package/dist-lib/agent-events.cjs +1 -1
  9. package/dist-lib/agent-identity.cjs +1 -1
  10. package/dist-lib/agent-sessions.cjs +1 -1
  11. package/dist-lib/attached-projects.cjs +1 -1
  12. package/dist-lib/auth/shared-session.cjs +1 -1
  13. package/dist-lib/backend-origin.cjs +1 -1
  14. package/dist-lib/beta.cjs +1 -1
  15. package/dist-lib/beta.mjs +1 -1
  16. package/dist-lib/bridge-constants.cjs +1 -1
  17. package/dist-lib/bridge-contract-input.cjs +1 -1
  18. package/dist-lib/bridge-contract-input.mjs +1 -1
  19. package/dist-lib/bridge-contract.cjs +1 -1
  20. package/dist-lib/bridge-contract.mjs +1 -1
  21. package/dist-lib/capture-contract.cjs +1 -1
  22. package/dist-lib/capture-contract.mjs +1 -1
  23. package/dist-lib/cli-constants.cjs +1 -1
  24. package/dist-lib/cloud-contract.cjs +1 -1
  25. package/dist-lib/cloud-contract.mjs +1 -1
  26. package/dist-lib/cloud-test-args.cjs +1 -1
  27. package/dist-lib/cloud-test-args.mjs +1 -1
  28. package/dist-lib/cloud.cjs +1 -1
  29. package/dist-lib/cloud.mjs +1 -1
  30. package/dist-lib/config.cjs +1 -1
  31. package/dist-lib/detox/index.cjs +1 -1
  32. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  33. package/dist-lib/home-paths.cjs +1 -1
  34. package/dist-lib/host/bridge-host.cjs +1 -1
  35. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  36. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  37. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  38. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  39. package/dist-lib/host/websocket-proxy.cjs +1 -1
  40. package/dist-lib/index.cjs +5 -1
  41. package/dist-lib/jump-to-source-babel.cjs +1 -1
  42. package/dist-lib/jump-to-source-native.cjs +1 -1
  43. package/dist-lib/kotlin-host.cjs +5 -1
  44. package/dist-lib/menu.cjs +1 -1
  45. package/dist-lib/menu.mjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  48. package/dist-lib/metro-production-bundle.cjs +1 -1
  49. package/dist-lib/metro-production-bundle.mjs +1 -1
  50. package/dist-lib/metro.cjs +1 -1
  51. package/dist-lib/native-app-identity.cjs +1 -1
  52. package/dist-lib/native-app-identity.mjs +1 -1
  53. package/dist-lib/plist.cjs +1 -1
  54. package/dist-lib/plist.mjs +1 -1
  55. package/dist-lib/profiles.cjs +1 -1
  56. package/dist-lib/public-brand.cjs +1 -1
  57. package/dist-lib/react-native-host-modules.cjs +1 -1
  58. package/dist-lib/react-native-host-modules.mjs +1 -1
  59. package/dist-lib/render-mode.cjs +1 -1
  60. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  61. package/dist-lib/sdk.cjs +1 -1
  62. package/dist-lib/sdk.mjs +1 -1
  63. package/dist-lib/skills.cjs +8 -4
  64. package/dist-lib/swift-compile.cjs +1 -1
  65. package/dist-lib/swift-compile.mjs +1 -1
  66. package/dist-lib/swift-package.cjs +1 -1
  67. package/dist-lib/swift-package.mjs +1 -1
  68. package/dist-lib/swift-submit.cjs +1 -1
  69. package/dist-lib/swift-submit.mjs +1 -1
  70. package/dist-lib/swift.cjs +1 -1
  71. package/dist-lib/vite-swift.cjs +1 -1
  72. package/dist-lib/vite.cjs +1 -1
  73. package/kotlin/AppSources/android/app/Activity.kt +48 -3
  74. package/kotlin/AppSources/android/app/Application.kt +4 -0
  75. package/kotlin/AppSources/android/content/res/Configuration.kt +4 -0
  76. package/kotlin/AppSources/android/content/res/Resources.kt +3 -1
  77. package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +36 -3
  78. package/kotlin/AppSources/dev/peach/app/PeachApp.kt +207 -73
  79. package/kotlin/ComposeSources/PeachComposeHost.kt +15 -3
  80. package/kotlin/fork/README.md +1 -0
  81. package/kotlin/fork/compose-worker-globals.patch +26 -0
  82. package/kotlin/fork/fork.json +1 -1
  83. package/kotlin/toolchain.json +3 -3
  84. package/package.json +1 -1
  85. package/src/kotlin-app.ts +7 -0
  86. package/src/kotlin-host.ts +4 -0
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/plist.ts
4
4
  import plistModule from "@expo/plist";
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/react-native-host-modules.ts
4
4
  var REACT_NATIVE_PASSTHROUGH_SPECIFIERS = [
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
package/dist-lib/sdk.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
package/dist-lib/sdk.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -31488,6 +31488,10 @@ var init_current_sim = __esm({
31488
31488
  // claude code, if ever set
31489
31489
  "CODEX_THREAD_ID",
31490
31490
  // codex / openai agent thread, stable across tool invocations
31491
+ // a Team Machine session, per agent run. its other runners set no session
31492
+ // variable of their own, and the terminal variables below are inherited from
31493
+ // whatever shell started the daemon, so every such agent would share one key.
31494
+ "TM_SESSION",
31491
31495
  "TERM_SESSION_ID",
31492
31496
  // macOS Terminal.app + iTerm2
31493
31497
  "ITERM_SESSION_ID",
@@ -36840,7 +36844,7 @@ async function runUseLikeCommand(args, opts = {}) {
36840
36844
  try {
36841
36845
  const sims = await bridge.listSims();
36842
36846
  const target = resolveTargetSim(sims, parsed.positional[0] || parsed.simId);
36843
- if (target.lockedBy && target.lockExpiresAt && target.lockExpiresAt > Date.now()) {
36847
+ if (target.lockedBy && !target.lockedByMe && target.lockExpiresAt && target.lockExpiresAt > Date.now()) {
36844
36848
  const secs = Math.max(0, Math.round((target.lockExpiresAt - Date.now()) / 1e3));
36845
36849
  if (target.lockedByKind === "user-active") {
36846
36850
  console.error(
@@ -36851,7 +36855,7 @@ async function runUseLikeCommand(args, opts = {}) {
36851
36855
  }
36852
36856
  if (!force) {
36853
36857
  console.error(
36854
- ` refused: ${target.id} is leased by ${target.lockedBy} (${secs}s)`
36858
+ ` refused: ${target.id} is leased by ${formatLockOwner(target.lockedBy)} (${secs}s)`
36855
36859
  );
36856
36860
  console.error(
36857
36861
  ` \`peach use ${target.id} --force\` to take it, or \`peach open --new\` for a fresh sim`
@@ -36891,7 +36895,7 @@ async function runClaimCommand(args, opts = {}) {
36891
36895
  try {
36892
36896
  const sims = await bridge.listSims();
36893
36897
  const target = resolveTargetSim(sims, parsed.positional[0] || parsed.simId);
36894
- const priorHolder = force && target.lockedBy && target.lockedByKind !== "user-active" ? target.lockedBy : null;
36898
+ const priorHolder = force && target.lockedBy && !target.lockedByMe && target.lockedByKind !== "user-active" ? target.lockedBy : null;
36895
36899
  const result = await bridge.claim(target.id, { force });
36896
36900
  saveCurrentSimId(target.id);
36897
36901
  const ttl = Math.max(0, Math.round((result.lockExpiresAt - Date.now()) / 1e3));
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/swift-compile.ts
4
4
  import { execFile as execFile2 } from "node:child_process";
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/swift-package.ts
4
4
  function isSwiftManifestFile(file) {
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/swift-submit.ts
4
4
  var SWIFT_COMPILE_PATH = "/api/swift-compile";
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
package/dist-lib/vite.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.659 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.660 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -3,6 +3,7 @@ package android.app
3
3
  import android.content.ComponentName
4
4
  import android.content.ContextWrapper
5
5
  import android.content.Intent
6
+ import android.content.res.Configuration
6
7
  import android.os.Bundle
7
8
  import android.util.SuperNotCalledException
8
9
  import android.view.View
@@ -28,11 +29,28 @@ open class Activity : ContextWrapper() {
28
29
  // still names the alias
29
30
  val componentName: ComponentName get() = checkNotNull(attachedComponent)
30
31
 
31
- internal fun attach(application: Application, component: ComponentName, intent: Intent, window: Window) {
32
+ // what the activity this one replaces returned from
33
+ // onRetainNonConfigurationInstance, across a configuration relaunch
34
+ var lastNonConfigurationInstance: Any? = null
35
+ private set
36
+
37
+ // true from the start of a configuration relaunch until this instance is
38
+ // destroyed, so its owners keep what the next instance takes over
39
+ var isChangingConfigurations = false
40
+ internal set
41
+
42
+ internal fun attach(
43
+ application: Application,
44
+ component: ComponentName,
45
+ intent: Intent,
46
+ window: Window,
47
+ lastNonConfigurationInstance: Any?,
48
+ ) {
32
49
  attachedApplication = application
33
50
  attachedComponent = component
34
51
  attachedIntent = intent
35
52
  attachedWindow = window
53
+ this.lastNonConfigurationInstance = lastNonConfigurationInstance
36
54
  }
37
55
 
38
56
  open fun setContentView(view: View) {
@@ -52,9 +70,18 @@ open class Activity : ContextWrapper() {
52
70
  protected open fun onStop() { called = true }
53
71
  protected open fun onRestart() { called = true }
54
72
 
55
- // Activity's own save writes the window's view hierarchy state; the decor
56
- // window here holds no view state of its own
73
+ protected open fun onDestroy() { called = true }
74
+
75
+ // a configuration change the manifest's configChanges lets it handle
76
+ // itself, without a relaunch
77
+ open fun onConfigurationChanged(newConfig: Configuration) { called = true }
78
+
79
+ // Activity's own save and restore carry the window's view hierarchy state;
80
+ // the decor window here holds no view state of its own
57
81
  protected open fun onSaveInstanceState(outState: Bundle) {}
82
+ protected open fun onRestoreInstanceState(savedInstanceState: Bundle) {}
83
+
84
+ open fun onRetainNonConfigurationInstance(): Any? = null
58
85
 
59
86
  // a back the window's callbacks left: the activity asks the task manager,
60
87
  // which moves a root launcher task to the back rather than finishing it
@@ -72,6 +99,7 @@ open class Activity : ContextWrapper() {
72
99
  internal open fun dispatchActivityPostResumed() {}
73
100
  internal open fun dispatchActivityPrePaused() {}
74
101
  internal open fun dispatchActivityPreStopped() {}
102
+ internal open fun dispatchActivityPreDestroyed() {}
75
103
 
76
104
  private fun require(method: String, call: () -> Unit) {
77
105
  called = false
@@ -112,6 +140,23 @@ open class Activity : ContextWrapper() {
112
140
  onSaveInstanceState(outState)
113
141
  }
114
142
 
143
+ // ActivityThread restores after onStart, only with saved state
144
+ internal fun performRestoreInstanceState(savedInstanceState: Bundle) {
145
+ onRestoreInstanceState(savedInstanceState)
146
+ }
147
+
148
+ // ActivityThread collects what the next instance keeps before onDestroy
149
+ internal fun retainNonConfigurationInstances(): Any? = onRetainNonConfigurationInstance()
150
+
151
+ internal fun performDestroy() {
152
+ dispatchActivityPreDestroyed()
153
+ require("onDestroy") { onDestroy() }
154
+ }
155
+
156
+ internal fun performConfigurationChanged(newConfig: Configuration) {
157
+ require("onConfigurationChanged") { onConfigurationChanged(newConfig) }
158
+ }
159
+
115
160
  // ActivityThread brings a stopped activity back with onRestart, then
116
161
  // onStart; one that never stopped has nothing to restart
117
162
  internal fun performRestart() {
@@ -1,7 +1,11 @@
1
1
  package android.app
2
2
 
3
3
  import android.content.ContextWrapper
4
+ import android.content.res.Configuration
4
5
 
5
6
  open class Application : ContextWrapper() {
6
7
  open fun onCreate() {}
8
+
9
+ // the process's configuration changed, before any activity relaunches
10
+ open fun onConfigurationChanged(newConfig: Configuration) {}
7
11
  }
@@ -5,6 +5,10 @@ package android.content.res
5
5
  class Configuration {
6
6
  var uiMode: Int = UI_MODE_TYPE_NORMAL or UI_MODE_NIGHT_NO
7
7
 
8
+ fun setTo(other: Configuration) {
9
+ uiMode = other.uiMode
10
+ }
11
+
8
12
  companion object {
9
13
  const val UI_MODE_TYPE_MASK = 0x0f
10
14
  const val UI_MODE_TYPE_NORMAL = 0x01
@@ -3,5 +3,7 @@ package android.content.res
3
3
  class Resources internal constructor(val configuration: Configuration)
4
4
 
5
5
  // the app process's resources, set once the device configuration is known at
6
- // cold start; every context in the process reads the same configuration
6
+ // cold start; every context in the process reads the same configuration, which
7
+ // a configuration change updates in place, as ResourcesManager does, so a
8
+ // Resources or Configuration an app holds reads the new values
7
9
  internal lateinit var processResources: Resources
@@ -29,8 +29,24 @@ open class ComponentActivity : Activity(), LifecycleOwner, ViewModelStoreOwner,
29
29
  private val lifecycleRegistry = LifecycleRegistry(this)
30
30
  private val savedStateRegistryController = SavedStateRegistryController.create(this)
31
31
 
32
+ // the last instance's store after a configuration relaunch, else a new one
33
+ private var _viewModelStore: ViewModelStore? = null
34
+
35
+ private class NonConfigurationInstances(val custom: Any?, val viewModelStore: ViewModelStore?)
36
+
32
37
  override val lifecycle: Lifecycle get() = lifecycleRegistry
33
- override val viewModelStore: ViewModelStore = ViewModelStore()
38
+ override val viewModelStore: ViewModelStore
39
+ get() {
40
+ ensureViewModelStore()
41
+ return checkNotNull(_viewModelStore)
42
+ }
43
+
44
+ private fun ensureViewModelStore() {
45
+ if (_viewModelStore == null) {
46
+ _viewModelStore = (lastNonConfigurationInstance as? NonConfigurationInstances)?.viewModelStore
47
+ ?: ViewModelStore()
48
+ }
49
+ }
34
50
  override val savedStateRegistry: SavedStateRegistry get() = savedStateRegistryController.savedStateRegistry
35
51
  override val defaultViewModelProviderFactory = SavedStateViewModelFactory()
36
52
  override val defaultViewModelCreationExtras: CreationExtras
@@ -41,17 +57,33 @@ open class ComponentActivity : Activity(), LifecycleOwner, ViewModelStoreOwner,
41
57
 
42
58
  init {
43
59
  lifecycleRegistry.addObserver(LifecycleEventObserver { _, event ->
44
- if (event == Lifecycle.Event.ON_DESTROY) viewModelStore.clear()
60
+ if (event == Lifecycle.Event.ON_DESTROY && !isChangingConfigurations) viewModelStore.clear()
45
61
  })
46
62
  savedStateRegistryController.performAttach()
47
63
  enableSavedStateHandles()
48
64
  }
49
65
 
50
66
  override fun onCreate(savedInstanceState: Bundle?) {
51
- savedStateRegistryController.performRestore(null)
67
+ savedStateRegistryController.performRestore(savedInstanceState?.state)
52
68
  super.onCreate(savedInstanceState)
53
69
  }
54
70
 
71
+ @Suppress("DEPRECATION")
72
+ final override fun onRetainNonConfigurationInstance(): Any? {
73
+ val custom = onRetainCustomNonConfigurationInstance()
74
+ val viewModelStore = _viewModelStore
75
+ ?: (lastNonConfigurationInstance as? NonConfigurationInstances)?.viewModelStore
76
+ if (viewModelStore == null && custom == null) return null
77
+ return NonConfigurationInstances(custom, viewModelStore)
78
+ }
79
+
80
+ @Deprecated("Use a ViewModel to store non config state.")
81
+ open fun onRetainCustomNonConfigurationInstance(): Any? = null
82
+
83
+ @Deprecated("Use a ViewModel to store non config state.")
84
+ open val lastCustomNonConfigurationInstance: Any?
85
+ get() = (lastNonConfigurationInstance as? NonConfigurationInstances)?.custom
86
+
55
87
  override fun onSaveInstanceState(outState: Bundle) {
56
88
  lifecycleRegistry.currentState = Lifecycle.State.CREATED
57
89
  super.onSaveInstanceState(outState)
@@ -73,4 +105,5 @@ open class ComponentActivity : Activity(), LifecycleOwner, ViewModelStoreOwner,
73
105
  override fun dispatchActivityPostResumed() = lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
74
106
  override fun dispatchActivityPrePaused() = lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
75
107
  override fun dispatchActivityPreStopped() = lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
108
+ override fun dispatchActivityPreDestroyed() = lifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
76
109
  }