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,
|
||||
},
|
||||
event,
|
||||
waitForDismiss: true,
|
||||
});
|
||||
|
||||
if (popoverData && popoverData.action) {
|
||||
|
@ -319,15 +320,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
|||
await this.confirmDiscard();
|
||||
this.setReplyFormData(this.post.id);
|
||||
|
||||
if (this.content) {
|
||||
setTimeout(() => {
|
||||
CoreDomUtils.scrollToElementBySelector(
|
||||
this.elementRef.nativeElement,
|
||||
this.content,
|
||||
'#addon-forum-reply-edit-form-' + this.uniqueId,
|
||||
);
|
||||
});
|
||||
}
|
||||
this.scrollToForm();
|
||||
} catch {
|
||||
// Cancelled.
|
||||
}
|
||||
|
@ -351,16 +344,7 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
|||
this.messageControl.setValue(this.replyData.message);
|
||||
}
|
||||
|
||||
if (this.content) {
|
||||
setTimeout(() => {
|
||||
CoreDomUtils.scrollToElementBySelector(
|
||||
this.elementRef.nativeElement,
|
||||
this.content,
|
||||
'#addon-forum-reply-edit-form-' + this.uniqueId,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
this.scrollToForm();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -382,6 +366,8 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
|||
this.post.attachments,
|
||||
this.post.isprivatereply,
|
||||
);
|
||||
|
||||
this.scrollToForm(5);
|
||||
} catch (error) {
|
||||
// Cancelled.
|
||||
}
|
||||
|
@ -600,4 +586,24 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy, OnChanges
|
|||
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.
|
||||
*
|
||||
* @param popoverOptions Modal Options.
|
||||
* @param options Options.
|
||||
*/
|
||||
async openPopover<T = void>(
|
||||
popoverOptions: PopoverOptions,
|
||||
options: OpenPopoverOptions,
|
||||
): 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);
|
||||
|
||||
await popover.present();
|
||||
|
@ -1743,16 +1743,16 @@ export class CoreDomUtilsProvider {
|
|||
if (zoomLevel !== CoreZoomLevel.NORMAL) {
|
||||
switch (getMode()) {
|
||||
case 'ios':
|
||||
fixIOSPopoverPosition(popover, popoverOptions.event);
|
||||
fixIOSPopoverPosition(popover, options.event);
|
||||
break;
|
||||
case 'md':
|
||||
fixMDPopoverPosition(popover, popoverOptions.event);
|
||||
fixMDPopoverPosition(popover, options.event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return result?.data;
|
||||
}
|
||||
|
@ -2046,3 +2046,10 @@ export const CoreDomUtils = makeSingleton(CoreDomUtilsProvider);
|
|||
|
||||
type AnchorOrMediaElement =
|
||||
HTMLAnchorElement | HTMLImageElement | HTMLAudioElement | HTMLVideoElement | HTMLSourceElement | HTMLTrackElement;
|
||||
|
||||
/**
|
||||
* Options for the openPopover function.
|
||||
*/
|
||||
export type OpenPopoverOptions = PopoverOptions & {
|
||||
waitForDismiss?: boolean;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue