MOBILE-3793 forum: Scroll to form when edit offline reply
parent
54abd2e0bc
commit
a068384867
|
@ -225,6 +225,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
cmId: this.forum.cmid,
|
cmId: this.forum.cmid,
|
||||||
},
|
},
|
||||||
event,
|
event,
|
||||||
|
waitForDismiss: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (popoverData && popoverData.action) {
|
if (popoverData && popoverData.action) {
|
||||||
|
@ -319,15 +320,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
await this.confirmDiscard();
|
await this.confirmDiscard();
|
||||||
this.setReplyFormData(this.post.id);
|
this.setReplyFormData(this.post.id);
|
||||||
|
|
||||||
if (this.content) {
|
this.scrollToForm();
|
||||||
setTimeout(() => {
|
|
||||||
CoreDomUtils.scrollToElementBySelector(
|
|
||||||
this.elementRef.nativeElement,
|
|
||||||
this.content,
|
|
||||||
'#addon-forum-reply-edit-form-' + this.uniqueId,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
// Cancelled.
|
// Cancelled.
|
||||||
}
|
}
|
||||||
|
@ -351,16 +344,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
this.messageControl.setValue(this.replyData.message);
|
this.messageControl.setValue(this.replyData.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.content) {
|
this.scrollToForm();
|
||||||
setTimeout(() => {
|
|
||||||
CoreDomUtils.scrollToElementBySelector(
|
|
||||||
this.elementRef.nativeElement,
|
|
||||||
this.content,
|
|
||||||
'#addon-forum-reply-edit-form-' + this.uniqueId,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -382,6 +366,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
this.post.attachments,
|
this.post.attachments,
|
||||||
this.post.isprivatereply,
|
this.post.isprivatereply,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.scrollToForm(5);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Cancelled.
|
// Cancelled.
|
||||||
}
|
}
|
||||||
|
@ -600,4 +586,24 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
||||||
delete this.replyData.syncId;
|
delete this.replyData.syncId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scroll to reply/edit form.
|
||||||
|
*
|
||||||
|
* @param ticksToWait Number of ticks to wait before scrolling.
|
||||||
|
* @return Promise resolved when done.
|
||||||
|
*/
|
||||||
|
protected async scrollToForm(ticksToWait = 1): Promise<void> {
|
||||||
|
if (!this.content) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await CoreUtils.nextTicks(ticksToWait);
|
||||||
|
|
||||||
|
CoreDomUtils.scrollToElementBySelector(
|
||||||
|
this.elementRef.nativeElement,
|
||||||
|
this.content,
|
||||||
|
'#addon-forum-reply-edit-form-' + this.uniqueId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1728,13 +1728,13 @@ export class CoreDomUtilsProvider {
|
||||||
/**
|
/**
|
||||||
* Opens a popover.
|
* Opens a popover.
|
||||||
*
|
*
|
||||||
* @param popoverOptions Modal Options.
|
* @param options Options.
|
||||||
*/
|
*/
|
||||||
async openPopover<T = void>(
|
async openPopover<T = void>(
|
||||||
popoverOptions: PopoverOptions,
|
options: OpenPopoverOptions,
|
||||||
): Promise<T | undefined> {
|
): Promise<T | undefined> {
|
||||||
|
|
||||||
const popover = await PopoverController.create(popoverOptions);
|
const popover = await PopoverController.create(options);
|
||||||
const zoomLevel = await CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NORMAL);
|
const zoomLevel = await CoreConfig.get(CoreConstants.SETTINGS_ZOOM_LEVEL, CoreZoomLevel.NORMAL);
|
||||||
|
|
||||||
await popover.present();
|
await popover.present();
|
||||||
|
@ -1743,16 +1743,16 @@ export class CoreDomUtilsProvider {
|
||||||
if (zoomLevel !== CoreZoomLevel.NORMAL) {
|
if (zoomLevel !== CoreZoomLevel.NORMAL) {
|
||||||
switch (getMode()) {
|
switch (getMode()) {
|
||||||
case 'ios':
|
case 'ios':
|
||||||
fixIOSPopoverPosition(popover, popoverOptions.event);
|
fixIOSPopoverPosition(popover, options.event);
|
||||||
break;
|
break;
|
||||||
case 'md':
|
case 'md':
|
||||||
fixMDPopoverPosition(popover, popoverOptions.event);
|
fixMDPopoverPosition(popover, options.event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If onDidDismiss is nedded we can add a new param to the function to wait one function or the other.
|
// If onDidDismiss is nedded we can add a new param to the function to wait one function or the other.
|
||||||
const result = await popover.onWillDismiss<T>();
|
const result = options.waitForDismiss ? await popover.onDidDismiss<T>() : await popover.onWillDismiss<T>();
|
||||||
if (result?.data) {
|
if (result?.data) {
|
||||||
return result?.data;
|
return result?.data;
|
||||||
}
|
}
|
||||||
|
@ -2046,3 +2046,10 @@ export const CoreDomUtils = makeSingleton(CoreDomUtilsProvider);
|
||||||
|
|
||||||
type AnchorOrMediaElement =
|
type AnchorOrMediaElement =
|
||||||
HTMLAnchorElement | HTMLImageElement | HTMLAudioElement | HTMLVideoElement | HTMLSourceElement | HTMLTrackElement;
|
HTMLAnchorElement | HTMLImageElement | HTMLAudioElement | HTMLVideoElement | HTMLSourceElement | HTMLTrackElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for the openPopover function.
|
||||||
|
*/
|
||||||
|
export type OpenPopoverOptions = PopoverOptions & {
|
||||||
|
waitForDismiss?: boolean;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue