Skip to content

Commit 2cf2591

Browse files
authored
Merge pull request #3564 from NoelDeMartin/MOBILE-2314
MOBILE-2314: Audio recorder improvements
2 parents 5824cf0 + a1cea17 commit 2cf2591

File tree

7 files changed

+47
-15
lines changed

7 files changed

+47
-15
lines changed

config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
</config-file>
199199
<config-file parent="/*" target="AndroidManifest.xml">
200200
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
201+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
201202
</config-file>
202203
<config-file parent="/*" target="AndroidManifest.xml">
203204
<queries>

src/core/components/sheet-modal/sheet-modal.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
height: 100%;
88
display: flex;
99
flex-direction: column;
10+
align-items: center;
1011
justify-content: flex-end;
1112
isolation: isolate;
1213

@@ -23,6 +24,8 @@
2324
z-index: 3; // ion-backdrop has z-index 2
2425
transform: translateY(100%);
2526
transition: transform 300ms ease-in;
27+
width: 100%;
28+
max-width: 500px;
2629
}
2730

2831
&.active {

src/core/components/sheet-modal/sheet-modal.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
3434

3535
private element: HTMLElement;
3636
private wrapperElement = new CorePromisedValue<HTMLElement>();
37+
private content?: HTMLElement;
3738

3839
constructor({ nativeElement: element }: ElementRef<HTMLElement>) {
3940
this.element = element;
@@ -61,7 +62,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
6162
*/
6263
async show(): Promise<T> {
6364
const wrapper = await this.wrapperElement;
64-
const element = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {});
65+
this.content = await AngularFrameworkDelegate.attachViewToDom(wrapper, this.component, this.componentProps ?? {});
6566

6667
await CoreUtils.nextTick();
6768

@@ -71,7 +72,7 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
7172
await CoreUtils.nextTick();
7273
await CoreUtils.wait(300);
7374

74-
const instance = CoreDirectivesRegistry.resolve(element, this.component);
75+
const instance = CoreDirectivesRegistry.resolve(this.content, this.component);
7576

7677
if (!instance) {
7778
throw new Error('Modal not mounted properly');
@@ -84,10 +85,13 @@ export class CoreSheetModalComponent<T extends CoreModalComponent> implements Af
8485
* Hide modal.
8586
*/
8687
async hide(): Promise<void> {
88+
const wrapper = await this.wrapperElement;
89+
8790
this.element.classList.remove('active');
8891

8992
await CoreUtils.nextTick();
9093
await CoreUtils.wait(300);
94+
await AngularFrameworkDelegate.removeViewFromDom(wrapper, this.content);
9195
}
9296

9397
}

src/core/features/fileuploader/components/audio-histogram/audio-histogram.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
--background-color: var(--ion-background-color, #fff);
33
--bars-color: var(--ion-text-color, #000);
44

5+
position: relative;
6+
57
canvas {
8+
position: absolute;
9+
top: 0;
10+
left: 0;
611
width: 100%;
712
height: 100%;
813
}

src/core/features/fileuploader/components/audio-histogram/audio-histogram.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,7 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
4848
this.context = this.canvas?.getContext('2d');
4949
this.buffer = new Uint8Array(this.analyser.fftSize);
5050

51-
if (this.context && this.canvas) {
52-
const styles = getComputedStyle(this.element);
53-
54-
this.canvas.width = this.canvas.clientWidth;
55-
this.canvas.height = this.canvas.clientHeight;
56-
this.context.fillStyle = styles.getPropertyValue('--background-color');
57-
this.context.lineCap = 'round';
58-
this.context.lineWidth = CoreFileUploaderAudioHistogramComponent.BARS_WIDTH;
59-
this.context.strokeStyle = styles.getPropertyValue('--bars-color');
60-
}
61-
51+
this.updateCanvas(this.element.clientWidth, this.element.clientHeight);
6252
this.draw();
6353
}
6454

@@ -77,6 +67,10 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
7767
return;
7868
}
7969

70+
if (this.canvas.width !== this.element.clientWidth || this.canvas.height !== this.element.clientHeight) {
71+
this.updateCanvas(this.element.clientWidth, this.element.clientHeight);
72+
}
73+
8074
const width = this.canvas.width;
8175
const height = this.canvas.height;
8276
const barsWidth = CoreFileUploaderAudioHistogramComponent.BARS_WIDTH;
@@ -157,4 +151,25 @@ export class CoreFileUploaderAudioHistogramComponent implements AfterViewInit, O
157151
}
158152
}
159153

154+
/**
155+
* Set canvas element dimensions and configure styles.
156+
*
157+
* @param width Canvas width.
158+
* @param height Canvas height.
159+
*/
160+
private updateCanvas(width: number, height: number): void {
161+
if (!this.canvas || !this.context) {
162+
return;
163+
}
164+
165+
const styles = getComputedStyle(this.element);
166+
167+
this.canvas.width = width;
168+
this.canvas.height = height;
169+
this.context.fillStyle = styles.getPropertyValue('--background-color');
170+
this.context.lineCap = 'round';
171+
this.context.lineWidth = CoreFileUploaderAudioHistogramComponent.BARS_WIDTH;
172+
this.context.strokeStyle = styles.getPropertyValue('--bars-color');
173+
}
174+
160175
}

src/core/features/fileuploader/components/audio-recorder/audio-recorder.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ export class CoreFileUploaderAudioRecorderComponent extends CoreModalComponent<C
8686
* @inheritdoc
8787
*/
8888
ngOnDestroy(): void {
89-
this.media$.value?.recorder.stop();
89+
const recorder = this.media$.value?.recorder;
90+
91+
if (recorder && recorder.state !== 'inactive') {
92+
recorder.stop();
93+
}
9094
}
9195

9296
/**

src/core/services/modals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ export class CoreModalsService {
7676

7777
modal.result.finally(async () => {
7878
await sheetModal.hide();
79+
await AngularFrameworkDelegate.removeViewFromDom(container, element);
7980

80-
element.remove();
8181
viewContainer?.removeAttribute('aria-hidden');
8282
});
8383

0 commit comments

Comments
 (0)