@api-client/ui 0.6.4 → 0.6.5

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.
@@ -4,6 +4,12 @@ import { FragmentManager } from './FragmentManager.js';
4
4
  import type { Fragment } from './Fragment.js';
5
5
  import type { Application, UpdateRequest } from './Application.js';
6
6
  import type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js';
7
+ export interface ActivityResult {
8
+ requestCode: number;
9
+ resultCode: IntentResult;
10
+ data?: unknown;
11
+ intent: Intent;
12
+ }
7
13
  /**
8
14
  * ## Activity
9
15
  *
@@ -70,13 +76,16 @@ export declare class Activity extends EventTarget {
70
76
  protected exitCode: IntentResult;
71
77
  /** Gets the current result code for the activity. */
72
78
  get resultCode(): IntentResult;
73
- /** Tracks pending request codes for activities started for result. */
74
- protected pendingRequestCodes: number[];
75
79
  /**
76
80
  * Constructs a new Activity.
77
81
  * @param parent The parent application instance.
78
82
  */
79
83
  constructor(parent: Application);
84
+ /**
85
+ * Returns the current activity instance.
86
+ * @returns This activity.
87
+ */
88
+ getActivity(): Activity;
80
89
  /**
81
90
  * Checks if the activity is in the `Destroyed` state.
82
91
  * @returns `true` if destroyed, `false` otherwise.
@@ -200,17 +209,20 @@ export declare class Activity extends EventTarget {
200
209
  * await this.startActivity({ action: 'login' });
201
210
  * ```
202
211
  */
203
- startActivity(intent: Intent): Promise<void>;
212
+ startActivity(intent: Intent): Promise<Activity>;
204
213
  /**
205
214
  * Starts a new activity for a result.
206
215
  * @param intent The intent to start.
207
- * @returns The request code for the started activity.
216
+ * @returns A promise that resolves when the started activity finishes, returning the result Intent.
208
217
  * @example
209
218
  * ```typescript
210
- * const code = await this.startActivityForResult({ action: 'pickFile' });
219
+ * const resultIntent = await this.startActivityForResult({ action: 'pickFile' });
220
+ * if (resultIntent.resultCode === IntentResult.RESULT_OK) {
221
+ * // handle result
222
+ * }
211
223
  * ```
212
224
  */
213
- startActivityForResult(intent: Intent): Promise<number>;
225
+ startActivityForResult(intent: Intent): Promise<Intent>;
214
226
  /**
215
227
  * Sets the result to be returned to the calling activity.
216
228
  * @param resultCode The result code.
@@ -221,33 +233,6 @@ export declare class Activity extends EventTarget {
221
233
  * ```
222
234
  */
223
235
  setResult(resultCode: IntentResult, data?: unknown): void;
224
- /**
225
- * Called when an activity you launched exits, giving you the request code, result code, and intent.
226
- * Override to handle results from started activities.
227
- * @param requestCode The request code.
228
- * @param resultCode The result code.
229
- * @param intent The intent that was used to start the activity.
230
- * @example
231
- * ```typescript
232
- * async onActivityResult(requestCode, resultCode, intent) {
233
- * if (resultCode === IntentResult.RESULT_OK) {
234
- * // handle result
235
- * }
236
- * }
237
- * ```
238
- */
239
- onActivityResult(requestCode: number, resultCode: IntentResult, intent: Intent): Promise<void>;
240
- /**
241
- * Returns the current activity instance.
242
- * @returns This activity.
243
- */
244
- getActivity(): Activity;
245
- /**
246
- * Checks if this activity initiated the activity for result with the given code.
247
- * @param code The request code.
248
- * @returns `true` if the code is pending, `false` otherwise.
249
- */
250
- hasRequestCode(code: number): boolean;
251
236
  /**
252
237
  * Gets the result data set by `setResult`.
253
238
  * @returns The result data or `undefined`.
@@ -1 +1 @@
1
- {"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAElE,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAGzF;;;;;;;;;;;;;;;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IACG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE;;;OAGG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9C;;;OAGG;IACH,cAAc,IAAI,WAAW;IAI7B;;;;;;;OAOG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKtD;;;;;;;;;;;OAWG;IACG,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK7D;;;;;;;;OAQG;IACH,SAAS,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAKzD;;;OAGG;IACH,SAAS,IAAI,OAAO,GAAG,SAAS;IAIhC;;;;;;;;;;;OAWG;IAEG,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,GAAG,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAWtG"}
@@ -83,8 +83,6 @@ let Activity = (() => {
83
83
  get resultCode() {
84
84
  return this.exitCode;
85
85
  }
86
- /** Tracks pending request codes for activities started for result. */
87
- pendingRequestCodes = [];
88
86
  /**
89
87
  * Constructs a new Activity.
90
88
  * @param parent The parent application instance.
@@ -94,6 +92,13 @@ let Activity = (() => {
94
92
  this.parent = parent;
95
93
  this.manager = new FragmentManager(this);
96
94
  }
95
+ /**
96
+ * Returns the current activity instance.
97
+ * @returns This activity.
98
+ */
99
+ getActivity() {
100
+ return this;
101
+ }
97
102
  /**
98
103
  * Checks if the activity is in the `Destroyed` state.
99
104
  * @returns `true` if destroyed, `false` otherwise.
@@ -261,24 +266,25 @@ let Activity = (() => {
261
266
  * await this.startActivity({ action: 'login' });
262
267
  * ```
263
268
  */
264
- startActivity(intent) {
265
- return this.parent.manager.startActivity(intent);
269
+ async startActivity(intent) {
270
+ const { manager } = this.getApplication();
271
+ return manager.startActivity(intent);
266
272
  }
267
273
  /**
268
274
  * Starts a new activity for a result.
269
275
  * @param intent The intent to start.
270
- * @returns The request code for the started activity.
276
+ * @returns A promise that resolves when the started activity finishes, returning the result Intent.
271
277
  * @example
272
278
  * ```typescript
273
- * const code = await this.startActivityForResult({ action: 'pickFile' });
279
+ * const resultIntent = await this.startActivityForResult({ action: 'pickFile' });
280
+ * if (resultIntent.resultCode === IntentResult.RESULT_OK) {
281
+ * // handle result
282
+ * }
274
283
  * ```
275
284
  */
276
285
  async startActivityForResult(intent) {
277
286
  const { manager } = this.getApplication();
278
- const code = manager.createRequestCode();
279
- this.pendingRequestCodes.push(code);
280
- await manager.startActivityForResult(intent, code);
281
- return code;
287
+ return manager.startActivityForResult(intent);
282
288
  }
283
289
  /**
284
290
  * Sets the result to be returned to the calling activity.
@@ -293,51 +299,6 @@ let Activity = (() => {
293
299
  this.exitCode = resultCode;
294
300
  this.resultData = data;
295
301
  }
296
- /**
297
- * Called when an activity you launched exits, giving you the request code, result code, and intent.
298
- * Override to handle results from started activities.
299
- * @param requestCode The request code.
300
- * @param resultCode The result code.
301
- * @param intent The intent that was used to start the activity.
302
- * @example
303
- * ```typescript
304
- * async onActivityResult(requestCode, resultCode, intent) {
305
- * if (resultCode === IntentResult.RESULT_OK) {
306
- * // handle result
307
- * }
308
- * }
309
- * ```
310
- */
311
- async onActivityResult(requestCode, resultCode, intent) {
312
- const index = this.pendingRequestCodes.indexOf(requestCode);
313
- if (index !== -1) {
314
- this.pendingRequestCodes.splice(index, 1);
315
- }
316
- // First we check whether any of the fragments has the code.
317
- const fragment = this.manager.findByRequestCode(requestCode);
318
- if (fragment) {
319
- return fragment.onActivityResult(requestCode, resultCode, intent);
320
- }
321
- if (this.constructor === Activity) {
322
- // eslint-disable-next-line no-console
323
- console.info(`Activity#onActivityResult not implemented. Request code: ${requestCode}, result code: ${resultCode}`, intent);
324
- }
325
- }
326
- /**
327
- * Returns the current activity instance.
328
- * @returns This activity.
329
- */
330
- getActivity() {
331
- return this;
332
- }
333
- /**
334
- * Checks if this activity initiated the activity for result with the given code.
335
- * @param code The request code.
336
- * @returns `true` if the code is pending, `false` otherwise.
337
- */
338
- hasRequestCode(code) {
339
- return this.pendingRequestCodes.includes(code);
340
- }
341
302
  /**
342
303
  * Gets the result data set by `setResult`.
343
304
  * @returns The result data or `undefined`.
@@ -360,7 +321,8 @@ let Activity = (() => {
360
321
  async handleIntentEvent(event) {
361
322
  if (event.type === EventTypes.Intent.startActivityForResult) {
362
323
  const info = event.detail;
363
- await this.startActivityForResult(info.intent);
324
+ const result = await this.startActivityForResult(info.intent);
325
+ info.onResult(IntentResult.RESULT_OK, result);
364
326
  }
365
327
  else if (event.type === EventTypes.Intent.startActivity) {
366
328
  await this.startActivity(event.detail.intent);
@@ -1 +1 @@
1
- {"version":3,"file":"Activity.js","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAGtD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;IACU,QAAQ;sBAAS,WAAW;;;iBAA5B,QAAS,SAAQ,WAAW;;;6CAwVtC,KAAK;YACN,sMAAM,iBAAiB,6DAStB;;;QAjWD;;;WAGG;QACH,UAAU,GALC,mDAAQ,CAKK;QAExB;;;;;;;;;;WAUG;QACH,MAAM,CAAC,MAAM,CAAS;QAEtB,mDAAmD;QAC5C,SAAS,GAAsB,iBAAiB,CAAC,WAAW,CAAA;QAEnE,uCAAuC;QAC7B,MAAM,CAAa;QAE7B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gBAC1D,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;;;SAlWU,QAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { nothing, TemplateResult } from 'lit'\nimport { ActivityLifecycle, IntentResult, type Intent } from './ActivityManager.js'\nimport { FragmentManager } from './FragmentManager.js'\nimport type { Fragment } from './Fragment.js'\nimport type { Application, UpdateRequest } from './Application.js'\nimport { bound } from '../decorators/bound.js'\nimport type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js'\nimport { EventTypes } from '../events/EventTypes.js'\n\n/**\n * ## Activity\n *\n * `Activity` is a core building block of your application, representing a single,\n * focused operation that a user can perform.\n * Activities manage their own lifecycle, UI, and fragments, and communicate with the application\n * and other activities via intents.\n *\n * Activities are managed by the application and can be started, paused, resumed, stopped,\n * and destroyed according to the app's navigation and user actions.\n * They can also start other activities for results, manage fragments, and handle intent\n * events dispatched by hosted web components.\n *\n * ### Lifecycle Methods\n * - `onCreate(intent?)` - Called when the activity is first created.\n * - `onStart()` - Called when the activity becomes visible to the user.\n * - `onResume()` - Called when the activity gains focus and becomes interactive.\n * - `onPause()` - Called when the activity loses focus but is still visible.\n * - `onStop()` - Called when the activity is no longer visible.\n * - `onDestroy()` - Called before the activity is destroyed.\n * - `onRestart()` - Called after the activity has been stopped, just prior to it being started again.\n *\n * ### Example\n * ```typescript\n * class MyActivity extends Activity {\n * async onCreate(intent?: Intent) {\n * super.onCreate(intent);\n * // Initialization logic here\n * }\n *\n * render() {\n * return html`<h1>Hello from MyActivity!</h1>`;\n * }\n * }\n * ```\n */\nexport class Activity extends EventTarget {\n /**\n * The root element where the activity's content should be rendered.\n * Set this if you want to render outside the application's default render root (e.g., for modals).\n */\n renderRoot?: HTMLElement\n\n /**\n * An optional static action name for the activity.\n * Use this as the registration key for referencing the activity in intents.\n *\n * @example\n * ```typescript\n * class LoginActivity extends Activity {\n * static action = 'login';\n * }\n * ```\n */\n static action?: string\n\n /** The current lifecycle state of the activity. */\n public lifecycle: ActivityLifecycle = ActivityLifecycle.Initialized\n\n /** The parent application instance. */\n protected parent: Application\n\n /** The fragment manager for managing fragments within this activity. */\n protected manager: FragmentManager\n\n /** Data to be returned as a result to the calling activity. */\n protected resultData?: unknown\n\n /** The exit code for the activity result. */\n protected exitCode = IntentResult.RESULT_CANCELED\n\n /** Gets the current result code for the activity. */\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /** Tracks pending request codes for activities started for result. */\n protected pendingRequestCodes: number[] = []\n\n /**\n * Constructs a new Activity.\n * @param parent The parent application instance.\n */\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Checks if the activity is in the `Destroyed` state.\n * @returns `true` if destroyed, `false` otherwise.\n */\n isDestroyed(): boolean {\n return this.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * Checks if the activity is in the `Resumed` state.\n * @returns `true` if resumed, `false` otherwise.\n */\n isResumed(): boolean {\n return this.lifecycle === ActivityLifecycle.Resumed\n }\n\n /**\n * Called when the activity is starting. Override to perform initialization logic.\n * @param intent Optional intent data.\n * @example\n * ```typescript\n * async onCreate(intent?: Intent) {\n * await fetchData();\n * }\n * ```\n */\n onCreate(intent?: Intent): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:create', { detail: intent }))\n }\n\n /**\n * Called when the activity becomes visible to the user.\n * Override to start animations or prepare UI.\n */\n onStart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:start', { detail: null }))\n }\n\n /**\n * Called when the activity gains focus and becomes interactive.\n * Override to start input handling or resume tasks.\n */\n onResume(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:resume', { detail: null }))\n }\n\n /**\n * Called when the activity loses focus but is still visible.\n * Override to pause ongoing tasks or save state.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when the activity is no longer visible to the user.\n * Override to stop UI updates or animations.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n /**\n * Called after the activity has been stopped, just prior to it being started again.\n */\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Called before the activity is destroyed. Override to clean up resources.\n */\n onDestroy(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:destroy', { detail: null }))\n this.manager.onDestroy()\n }\n\n /**\n * Called when a new intent is delivered to the activity.\n * Override to handle new intents.\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n // Override in subclass if needed\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n * Override to perform actions after first render.\n */\n onFirstRender(): void {\n // Override in subclass if needed\n }\n\n /**\n * Renders the activity's view. Override to provide UI.\n * @returns A Lit TemplateResult or `nothing` if nothing should be rendered.\n * @example\n * ```typescript\n * render() {\n * return html`<div>Hello, world!</div>`;\n * }\n * ```\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity and notifies the application.\n * @example\n * ```typescript\n * await this.finish();\n * ```\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * Requests the parent application to update the UI.\n * @param opts Update options.\n * @example\n * ```typescript\n * this.requestUpdate();\n * ```\n */\n requestUpdate(opts: UpdateRequest = {}): void {\n const { activity = true } = opts\n if (activity) {\n this.manager.updateActiveFragments()\n }\n this.parent.requestUpdate(opts)\n }\n\n /**\n * Registers a new fragment with this activity.\n * @param key The fragment's key.\n * @param fragment The fragment instance.\n * @param data Optional data to pass to the fragment.\n * @example\n * ```typescript\n * await this.addFragment('profile', new ProfileFragment());\n * ```\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n /**\n * Shows a registered fragment.\n * @param key The fragment's key.\n * @param root Optional root element to render into.\n */\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\n\n /**\n * Hides a registered fragment.\n * @param key The fragment's key.\n */\n async hideFragment(key: string): Promise<void> {\n const fragment = this.manager.findFragment(key)\n if (fragment) {\n await this.manager.hideFragment(fragment)\n }\n }\n\n /**\n * Returns the parent application instance.\n * @returns The application.\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * Starts a new activity.\n * @param intent The intent to start.\n * @example\n * ```typescript\n * await this.startActivity({ action: 'login' });\n * ```\n */\n startActivity(intent: Intent): Promise<void> {\n return this.parent.manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @param intent The intent to start.\n * @returns The request code for the started activity.\n * @example\n * ```typescript\n * const code = await this.startActivityForResult({ action: 'pickFile' });\n * ```\n */\n async startActivityForResult(intent: Intent): Promise<number> {\n const { manager } = this.getApplication()\n const code = manager.createRequestCode()\n this.pendingRequestCodes.push(code)\n await manager.startActivityForResult(intent, code)\n return code\n }\n\n /**\n * Sets the result to be returned to the calling activity.\n * @param resultCode The result code.\n * @param data Optional result data.\n * @example\n * ```typescript\n * this.setResult(IntentResult.RESULT_OK, { userId: 123 });\n * ```\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Called when an activity you launched exits, giving you the request code, result code, and intent.\n * Override to handle results from started activities.\n * @param requestCode The request code.\n * @param resultCode The result code.\n * @param intent The intent that was used to start the activity.\n * @example\n * ```typescript\n * async onActivityResult(requestCode, resultCode, intent) {\n * if (resultCode === IntentResult.RESULT_OK) {\n * // handle result\n * }\n * }\n * ```\n */\n async onActivityResult(requestCode: number, resultCode: IntentResult, intent: Intent): Promise<void> {\n const index = this.pendingRequestCodes.indexOf(requestCode)\n if (index !== -1) {\n this.pendingRequestCodes.splice(index, 1)\n }\n // First we check whether any of the fragments has the code.\n const fragment = this.manager.findByRequestCode(requestCode)\n if (fragment) {\n return fragment.onActivityResult(requestCode, resultCode, intent)\n }\n if (this.constructor === Activity) {\n // eslint-disable-next-line no-console\n console.info(\n `Activity#onActivityResult not implemented. Request code: ${requestCode}, result code: ${resultCode}`,\n intent\n )\n }\n }\n\n /**\n * Returns the current activity instance.\n * @returns This activity.\n */\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks if this activity initiated the activity for result with the given code.\n * @param code The request code.\n * @returns `true` if the code is pending, `false` otherwise.\n */\n hasRequestCode(code: number): boolean {\n return this.pendingRequestCodes.includes(code)\n }\n\n /**\n * Gets the result data set by `setResult`.\n * @returns The result data or `undefined`.\n */\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * Handles intent events dispatched by web components hosted by this activity.\n *\n * Usage example:\n * ```html\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The intent event.\n * @throws Error if the event type is not recognized.\n */\n @bound\n async handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void> {\n if (event.type === EventTypes.Intent.startActivityForResult) {\n const info = event.detail as ActivityWithResultDetail\n await this.startActivityForResult(info.intent)\n } else if (event.type === EventTypes.Intent.startActivity) {\n await this.startActivity(event.detail.intent)\n } else {\n throw new Error(`Unrecognized intent event: ${event.type}`)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Activity.js","sourceRoot":"","sources":["../../../src/core/Activity.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,OAAO,EAAE,OAAO,EAAkB,MAAM,KAAK,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAe,MAAM,sBAAsB,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CA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Ac;YACzC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,CAAA;YACzC,OAAO,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED;;;;;;;;WAQG;QACH,SAAS,CAAC,UAAwB,EAAE,IAAc;YAChD,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAA;YAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACxB,CAAC;QAED;;;WAGG;QACH,SAAS;YACP,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QAED;;;;;;;;;;;WAWG;QAEH,KAAK,CAAC,iBAAiB,CAAC,KAA6D;YACnF,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC;gBAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,MAAkC,CAAA;gBACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAC7D,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;gBAC1D,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAC/C,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;;;SAtTU,QAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { nothing, TemplateResult } from 'lit'\nimport { ActivityLifecycle, IntentResult, type Intent } from './ActivityManager.js'\nimport { FragmentManager } from './FragmentManager.js'\nimport type { Fragment } from './Fragment.js'\nimport type { Application, UpdateRequest } from './Application.js'\nimport { bound } from '../decorators/bound.js'\nimport type { ActivityDetail, ActivityWithResultDetail } from '../events/IntentEvents.js'\nimport { EventTypes } from '../events/EventTypes.js'\n\nexport interface ActivityResult {\n requestCode: number\n resultCode: IntentResult\n data?: unknown\n intent: Intent\n}\n\n/**\n * ## Activity\n *\n * `Activity` is a core building block of your application, representing a single,\n * focused operation that a user can perform.\n * Activities manage their own lifecycle, UI, and fragments, and communicate with the application\n * and other activities via intents.\n *\n * Activities are managed by the application and can be started, paused, resumed, stopped,\n * and destroyed according to the app's navigation and user actions.\n * They can also start other activities for results, manage fragments, and handle intent\n * events dispatched by hosted web components.\n *\n * ### Lifecycle Methods\n * - `onCreate(intent?)` - Called when the activity is first created.\n * - `onStart()` - Called when the activity becomes visible to the user.\n * - `onResume()` - Called when the activity gains focus and becomes interactive.\n * - `onPause()` - Called when the activity loses focus but is still visible.\n * - `onStop()` - Called when the activity is no longer visible.\n * - `onDestroy()` - Called before the activity is destroyed.\n * - `onRestart()` - Called after the activity has been stopped, just prior to it being started again.\n *\n * ### Example\n * ```typescript\n * class MyActivity extends Activity {\n * async onCreate(intent?: Intent) {\n * super.onCreate(intent);\n * // Initialization logic here\n * }\n *\n * render() {\n * return html`<h1>Hello from MyActivity!</h1>`;\n * }\n * }\n * ```\n */\nexport class Activity extends EventTarget {\n /**\n * The root element where the activity's content should be rendered.\n * Set this if you want to render outside the application's default render root (e.g., for modals).\n */\n renderRoot?: HTMLElement\n\n /**\n * An optional static action name for the activity.\n * Use this as the registration key for referencing the activity in intents.\n *\n * @example\n * ```typescript\n * class LoginActivity extends Activity {\n * static action = 'login';\n * }\n * ```\n */\n static action?: string\n\n /** The current lifecycle state of the activity. */\n public lifecycle: ActivityLifecycle = ActivityLifecycle.Initialized\n\n /** The parent application instance. */\n protected parent: Application\n\n /** The fragment manager for managing fragments within this activity. */\n protected manager: FragmentManager\n\n /** Data to be returned as a result to the calling activity. */\n protected resultData?: unknown\n\n /** The exit code for the activity result. */\n protected exitCode = IntentResult.RESULT_CANCELED\n\n /** Gets the current result code for the activity. */\n get resultCode(): IntentResult {\n return this.exitCode\n }\n\n /**\n * Constructs a new Activity.\n * @param parent The parent application instance.\n */\n constructor(parent: Application) {\n super()\n this.parent = parent\n this.manager = new FragmentManager(this)\n }\n\n /**\n * Returns the current activity instance.\n * @returns This activity.\n */\n getActivity(): Activity {\n return this\n }\n\n /**\n * Checks if the activity is in the `Destroyed` state.\n * @returns `true` if destroyed, `false` otherwise.\n */\n isDestroyed(): boolean {\n return this.lifecycle === ActivityLifecycle.Destroyed\n }\n\n /**\n * Checks if the activity is in the `Resumed` state.\n * @returns `true` if resumed, `false` otherwise.\n */\n isResumed(): boolean {\n return this.lifecycle === ActivityLifecycle.Resumed\n }\n\n /**\n * Called when the activity is starting. Override to perform initialization logic.\n * @param intent Optional intent data.\n * @example\n * ```typescript\n * async onCreate(intent?: Intent) {\n * await fetchData();\n * }\n * ```\n */\n onCreate(intent?: Intent): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:create', { detail: intent }))\n }\n\n /**\n * Called when the activity becomes visible to the user.\n * Override to start animations or prepare UI.\n */\n onStart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:start', { detail: null }))\n }\n\n /**\n * Called when the activity gains focus and becomes interactive.\n * Override to start input handling or resume tasks.\n */\n onResume(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:resume', { detail: null }))\n }\n\n /**\n * Called when the activity loses focus but is still visible.\n * Override to pause ongoing tasks or save state.\n */\n onPause(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:pause', { detail: null }))\n }\n\n /**\n * Called when the activity is no longer visible to the user.\n * Override to stop UI updates or animations.\n */\n onStop(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:stop', { detail: null }))\n }\n\n /**\n * Called after the activity has been stopped, just prior to it being started again.\n */\n onRestart(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:restart', { detail: null }))\n }\n\n /**\n * Called before the activity is destroyed. Override to clean up resources.\n */\n onDestroy(): void | Promise<void> {\n this.dispatchEvent(new CustomEvent('activity:destroy', { detail: null }))\n this.manager.onDestroy()\n }\n\n /**\n * Called when a new intent is delivered to the activity.\n * Override to handle new intents.\n * @param intent New intent data.\n */\n onNewIntent(intent: Intent): void | Promise<void> {\n // Override in subclass if needed\n }\n\n /**\n * Called by the renderer when the activity is rendered for the first time.\n * Override to perform actions after first render.\n */\n onFirstRender(): void {\n // Override in subclass if needed\n }\n\n /**\n * Renders the activity's view. Override to provide UI.\n * @returns A Lit TemplateResult or `nothing` if nothing should be rendered.\n * @example\n * ```typescript\n * render() {\n * return html`<div>Hello, world!</div>`;\n * }\n * ```\n */\n render(): TemplateResult | typeof nothing {\n return nothing\n }\n\n /**\n * Finishes the activity and notifies the application.\n * @example\n * ```typescript\n * await this.finish();\n * ```\n */\n async finish(): Promise<void> {\n await this.getApplication().manager.finishActivity(this)\n }\n\n /**\n * Requests the parent application to update the UI.\n * @param opts Update options.\n * @example\n * ```typescript\n * this.requestUpdate();\n * ```\n */\n requestUpdate(opts: UpdateRequest = {}): void {\n const { activity = true } = opts\n if (activity) {\n this.manager.updateActiveFragments()\n }\n this.parent.requestUpdate(opts)\n }\n\n /**\n * Registers a new fragment with this activity.\n * @param key The fragment's key.\n * @param fragment The fragment instance.\n * @param data Optional data to pass to the fragment.\n * @example\n * ```typescript\n * await this.addFragment('profile', new ProfileFragment());\n * ```\n */\n async addFragment(key: string, fragment: Fragment, data?: unknown): Promise<void> {\n await this.manager.attachFragment(key, fragment, this, data)\n }\n\n /**\n * Shows a registered fragment.\n * @param key The fragment's key.\n * @param root Optional root element to render into.\n */\n async showFragment(key: string, root?: HTMLElement): Promise<void> {\n await this.manager.showFragment(key, root)\n }\n\n /**\n * Hides a registered fragment.\n * @param key The fragment's key.\n */\n async hideFragment(key: string): Promise<void> {\n const fragment = this.manager.findFragment(key)\n if (fragment) {\n await this.manager.hideFragment(fragment)\n }\n }\n\n /**\n * Returns the parent application instance.\n * @returns The application.\n */\n getApplication(): Application {\n return this.parent\n }\n\n /**\n * Starts a new activity.\n * @param intent The intent to start.\n * @example\n * ```typescript\n * await this.startActivity({ action: 'login' });\n * ```\n */\n async startActivity(intent: Intent): Promise<Activity> {\n const { manager } = this.getApplication()\n return manager.startActivity(intent)\n }\n\n /**\n * Starts a new activity for a result.\n * @param intent The intent to start.\n * @returns A promise that resolves when the started activity finishes, returning the result Intent.\n * @example\n * ```typescript\n * const resultIntent = await this.startActivityForResult({ action: 'pickFile' });\n * if (resultIntent.resultCode === IntentResult.RESULT_OK) {\n * // handle result\n * }\n * ```\n */\n async startActivityForResult(intent: Intent): Promise<Intent> {\n const { manager } = this.getApplication()\n return manager.startActivityForResult(intent)\n }\n\n /**\n * Sets the result to be returned to the calling activity.\n * @param resultCode The result code.\n * @param data Optional result data.\n * @example\n * ```typescript\n * this.setResult(IntentResult.RESULT_OK, { userId: 123 });\n * ```\n */\n setResult(resultCode: IntentResult, data?: unknown): void {\n this.exitCode = resultCode\n this.resultData = data\n }\n\n /**\n * Gets the result data set by `setResult`.\n * @returns The result data or `undefined`.\n */\n getResult(): unknown | undefined {\n return this.resultData\n }\n\n /**\n * Handles intent events dispatched by web components hosted by this activity.\n *\n * Usage example:\n * ```html\n * <custom-element @startactivity=\"${this.handleIntentEvent}\"></custom-element>\n * <custom-element @startactivityforresult=\"${this.handleIntentEvent}\"></custom-element>\n * ```\n *\n * @param event The intent event.\n * @throws Error if the event type is not recognized.\n */\n @bound\n async handleIntentEvent(event: CustomEvent<ActivityDetail | ActivityWithResultDetail>): Promise<void> {\n if (event.type === EventTypes.Intent.startActivityForResult) {\n const info = event.detail as ActivityWithResultDetail\n const result = await this.startActivityForResult(info.intent)\n info.onResult(IntentResult.RESULT_OK, result)\n } else if (event.type === EventTypes.Intent.startActivity) {\n await this.startActivity(event.detail.intent)\n } else {\n throw new Error(`Unrecognized intent event: ${event.type}`)\n }\n }\n}\n"]}
@@ -101,6 +101,10 @@ export declare class ActivityManager {
101
101
  * Stores activity *classes* by unique ID (action name).
102
102
  */
103
103
  private activityClasses;
104
+ /**
105
+ * Stores the resolvers for activities started for result.
106
+ */
107
+ private resultResolvers;
104
108
  /**
105
109
  * Represents the activity stack. It is used to manage
106
110
  * the UI state after calling the back action.
@@ -131,27 +135,25 @@ export declare class ActivityManager {
131
135
  * @param intent The intent that created this activity.
132
136
  */
133
137
  createActivity(intent: Intent): Promise<void>;
134
- setupRoute(intent: Intent): void;
135
138
  /**
136
139
  * Starts a new activity and brings it to the foreground.
137
140
  *
138
141
  * @param intent The intent that created this activity.
139
142
  */
140
- startActivity(intent: Intent): Promise<void>;
143
+ startActivity(intent: Intent): Promise<Activity>;
141
144
  private buildActivity;
142
145
  /**
143
146
  * Starts an activity that should return a result to the calling activity.
144
- * The result should be a unique number across the application.
147
+ *
145
148
  * @param intent The intent to start the activity.
146
- * @param requestCode The request code used to match the activity result.
147
149
  */
148
- startActivityForResult(intent: Intent, requestCode: number): Promise<void>;
150
+ startActivityForResult(intent: Intent): Promise<Intent>;
149
151
  isDestroyed(activity: Activity): boolean;
150
152
  /**
151
153
  * @param activity The activity to finish.
152
154
  */
153
155
  finishActivity(activity: Activity): Promise<void>;
154
- private manageActivityResult;
156
+ private resolveActivityResult;
155
157
  private bringLastActivityToFront;
156
158
  getTopActivity(): Activity | undefined;
157
159
  getCurrentActivity(): Activity | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ActivityManager.d.ts","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,oBAAY,iBAAiB;IAC3B;;;OAGG;IACH,WAAW,IAAA;IACX;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;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CAAC;IAYZ,iBAAiB,IAAI,MAAM;IAM3B,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIxD;;;;OAIG;YACW,0BAA0B;IAgBxC;;;;OAIG;YACW,0BAA0B;IAUxC;;;;;OAKG;YACW,8BAA8B;IAU5C;;;OAGG;IACH,OAAO,CAAC,eAAe;IAevB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAsBhC;;;;OAIG;IACH,cAAc,IAAI;QAChB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,EAAE,MAAM,EAAE,CAAA;QACzB,oBAAoB,EAAE,MAAM,EAAE,CAAA;KAC/B;IAWD;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;;;OAIG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAG5C"}
1
+ {"version":3,"file":"ActivityManager.d.ts","sourceRoot":"","sources":["../../../src/core/ActivityManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAGnD,oBAAY,iBAAiB;IAC3B;;;OAGG;IACH,WAAW,IAAA;IACX;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,MAAM,IAAA;IACN;;;OAGG;IACH,OAAO,IAAA;IACP;;;OAGG;IACH,SAAS,IAAA;CACV;AAED,oBAAY,WAAW;IACrB;;OAEG;IACH,KAAK,IAAS;IACd;;OAEG;IACH,SAAS,IAAS;IAClB;;;;;OAKG;IACH,WAAW,IAAS;CACrB;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAA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O,CAAC,wBAAwB;IAsBhC;;;;OAIG;IACH,cAAc,IAAI;QAChB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,EAAE,MAAM,CAAA;QACvB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,eAAe,EAAE,MAAM,EAAE,CAAA;QACzB,oBAAoB,EAAE,MAAM,EAAE,CAAA;KAC/B;IAWD;;;OAGG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;;;OAIG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAG5C"}
@@ -1,4 +1,4 @@
1
- import { navigateScreen } from './ApplicationRoute.js';
1
+ // import { navigateScreen } from './ApplicationRoute.js'
2
2
  export var ActivityLifecycle;
3
3
  (function (ActivityLifecycle) {
4
4
  /**
@@ -76,6 +76,10 @@ export class ActivityManager {
76
76
  * Stores activity *classes* by unique ID (action name).
77
77
  */
78
78
  activityClasses = new Map();
79
+ /**
80
+ * Stores the resolvers for activities started for result.
81
+ */
82
+ resultResolvers = new Map();
79
83
  /**
80
84
  * Represents the activity stack. It is used to manage
81
85
  * the UI state after calling the back action.
@@ -113,14 +117,6 @@ export class ActivityManager {
113
117
  }
114
118
  this.activityClasses.set(action, activityClass);
115
119
  }
116
- // protected reflectEvent<T extends Event>(event: T): T {
117
- // const copy = Reflect.construct(event.constructor, [event.type, event])
118
- // const dispatched = this.#parent.events.dispatchEvent(copy)
119
- // if (!dispatched) {
120
- // event.preventDefault()
121
- // }
122
- // return copy
123
- // }
124
120
  /**
125
121
  * Creates an activity and pushes it into the stack, but it does not initialize any of the lifecycle methods.
126
122
  * It is a way to put an activity at some place of the stack,
@@ -137,14 +133,14 @@ export class ActivityManager {
137
133
  const stackEntry = { activity, id: activityId, intent, action: intent.action };
138
134
  this.activityStack.push(stackEntry);
139
135
  }
140
- setupRoute(intent) {
141
- if (intent.data) {
142
- const typed = intent.data;
143
- if (typed.uri) {
144
- navigateScreen(typed.uri);
145
- }
146
- }
147
- }
136
+ // setupRoute(intent: Intent): void {
137
+ // if (intent.data) {
138
+ // const typed = intent.data as { uri?: string }
139
+ // if (typed.uri) {
140
+ // navigateScreen(typed.uri)
141
+ // }
142
+ // }
143
+ // }
148
144
  /**
149
145
  * Starts a new activity and brings it to the foreground.
150
146
  *
@@ -165,9 +161,9 @@ export class ActivityManager {
165
161
  });
166
162
  await info.activity.onNewIntent(intent);
167
163
  // TODO: Check if the activity is destroyed.
168
- this.setupRoute(intent);
164
+ // this.setupRoute(intent)
169
165
  await this.updateCurrentActivity(info.activity, false);
170
- return;
166
+ return info.activity;
171
167
  }
172
168
  const activity = this.buildActivity(intent);
173
169
  if (currentActivity) {
@@ -189,15 +185,16 @@ export class ActivityManager {
189
185
  await activity.onCreate(intent);
190
186
  if (this.isDestroyed(activity)) {
191
187
  // the activity finished and the manager already took care of this situation.
192
- return;
188
+ return activity;
193
189
  }
194
190
  activity.lifecycle = ActivityLifecycle.Created;
195
191
  await this.updateCurrentActivity(activity, !!isModal);
196
192
  if (this.isDestroyed(activity)) {
197
193
  // the activity finished and the manager already took care of this situation.
198
- return;
194
+ return activity;
199
195
  }
200
- this.setupRoute(intent);
196
+ // this.setupRoute(intent)
197
+ return activity;
201
198
  }
202
199
  buildActivity(intent) {
203
200
  const action = intent.action;
@@ -214,12 +211,10 @@ export class ActivityManager {
214
211
  }
215
212
  /**
216
213
  * Starts an activity that should return a result to the calling activity.
217
- * The result should be a unique number across the application.
214
+ *
218
215
  * @param intent The intent to start the activity.
219
- * @param requestCode The request code used to match the activity result.
220
216
  */
221
- async startActivityForResult(intent, requestCode) {
222
- intent.requestCode = requestCode;
217
+ async startActivityForResult(intent) {
223
218
  const byReference = (intent.flags ?? 0) & IntentFlags.ByReference;
224
219
  const shallowCopy = { ...intent };
225
220
  const data = shallowCopy.data;
@@ -236,7 +231,13 @@ export class ActivityManager {
236
231
  else {
237
232
  deepCopy.flags = IntentFlags.ForResult;
238
233
  }
239
- await this.startActivity(deepCopy);
234
+ return new Promise((resolve, reject) => {
235
+ this.resultResolvers.set(deepCopy, resolve);
236
+ this.startActivity(deepCopy).catch((e) => {
237
+ this.resultResolvers.delete(deepCopy);
238
+ reject(e);
239
+ });
240
+ });
240
241
  }
241
242
  isDestroyed(activity) {
242
243
  return activity.lifecycle === ActivityLifecycle.Destroyed;
@@ -259,7 +260,7 @@ export class ActivityManager {
259
260
  stackEntry.activity.lifecycle = ActivityLifecycle.Destroyed;
260
261
  // Clean up resources to prevent memory leaks
261
262
  this.cleanupActivity(stackEntry.activity);
262
- await this.manageActivityResult(stackEntry.activity, stackEntry.intent);
263
+ this.resolveActivityResult(stackEntry.activity, stackEntry.intent);
263
264
  // Resume the previous activity
264
265
  await this.bringLastActivityToFront();
265
266
  }
@@ -270,31 +271,27 @@ export class ActivityManager {
270
271
  }
271
272
  await activity.onDestroy();
272
273
  activity.lifecycle = ActivityLifecycle.Destroyed;
274
+ this.resolveActivityResult(activity, { action: '' });
273
275
  // This can happen when an activity finishes in one of the callback methods,
274
276
  // before it is added to the stack. In that case, we bring the last activity back to the front.
275
277
  await this.bringLastActivityToFront();
276
278
  }
277
279
  this.#parent.requestUpdate();
278
280
  }
279
- async manageActivityResult(activity, intent) {
280
- const { flags = 0, requestCode = -1 } = intent;
281
- if (flags & IntentFlags.ForResult) {
282
- const all = [...this.activityStack, ...this.modalActivityStack];
283
- const target = all.find((entry) => entry.activity.hasRequestCode(requestCode));
284
- if (target) {
285
- if (target.activity.lifecycle === ActivityLifecycle.Destroyed) {
286
- return;
287
- }
288
- if (target.activity.lifecycle === ActivityLifecycle.Resumed) {
289
- await target.activity.onPause();
290
- target.activity.lifecycle = ActivityLifecycle.Paused;
291
- }
292
- // Let's create a shallow copy of the intent. We can disregard the ByReference flag here,
293
- // as we override the data with the result data.
294
- const intentCopy = { ...intent };
295
- intentCopy.data = activity.getResult();
296
- await target.activity.onActivityResult(requestCode, activity.resultCode, intentCopy);
297
- }
281
+ resolveActivityResult(activity, originalIntent) {
282
+ const resolver = this.resultResolvers.get(originalIntent);
283
+ // The activity might have not been started with startActivityForResult.
284
+ // A thing to consider for the future is whether we should throw an error in a case where
285
+ // the activity was started for result but the resolver was not found.
286
+ if (resolver) {
287
+ this.resultResolvers.delete(originalIntent);
288
+ // We construct the result intent.
289
+ // Ideally we would like to preserve the original intent structure but with new data.
290
+ const resultIntent = {
291
+ ...originalIntent,
292
+ data: activity.getResult(),
293
+ };
294
+ resolver(resultIntent);
298
295
  }
299
296
  }
300
297
  async bringLastActivityToFront() {