Skip to content

Commit

Permalink
Merge pull request #4054 from dpalou/MOBILE-4470
Browse files Browse the repository at this point in the history
Mobile 4470
  • Loading branch information
crazyserver authored May 21, 2024
2 parents e511629 + fb7f637 commit e8457e8
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/components/iframe/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class CoreIframeComponent implements OnChanges, OnDestroy {

@Input() src?: string;
@Input() id: string | null = null;
@Input() iframeWidth?: string;
@Input() iframeHeight?: string;
@Input() iframeWidth = '100%';
@Input() iframeHeight = '100%';
@Input() allowFullscreen?: boolean | string;
@Input() showFullscreenOnToolbar?: boolean | string;
@Input() autoFullscreenOnRotate?: boolean | string;
Expand Down
9 changes: 9 additions & 0 deletions src/core/components/tabs-outlet/tabs-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { StackDidChangeEvent } from '@ionic/angular/common/directives/navigation
import { CoreNavigator } from '@services/navigator';
import { CoreTabBase, CoreTabsBaseComponent } from '@classes/tabs';
import { CoreDirectivesRegistry } from '@singletons/directives-registry';
import { CorePath } from '@singletons/path';

/**
* This component displays some top scrollable tabs that will autohide on vertical scroll.
Expand Down Expand Up @@ -143,6 +144,14 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent<CoreTabsOutle
// After the view has entered for the first time, we can assume that it'll always be in the navigation stack
// until it's destroyed.
this.existsInNavigationStack = true;

const selectedTab = this.getSelected();
const currentPath = CoreNavigator.getCurrentPath();
if (selectedTab && CorePath.pathIsAncestor(currentPath, selectedTab.page)) {
// Current path is an ancestor of the selected path, this happens when the user changes main menu tab and comes back.
// Load the tab again so the right route is loaded. This only changes the current route, it doesn't reload the page.
this.loadTab(selectedTab);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/core/features/viewer/components/image/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<swiper-container #swiperRef>
<swiper-slide>
<div class="swiper-zoom-container">
@if (dataUrl) {
<img [src]="dataUrl" [alt]="title">
} @else {
<img [url]="image" [alt]="title" core-external-content [component]="component" [componentId]="componentId">
}
</div>
</swiper-slide>
</swiper-container>
Expand Down
11 changes: 10 additions & 1 deletion src/core/features/viewer/components/image/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
// limitations under the License.

import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { ModalController, Translate } from '@singletons';
import { DomSanitizer, ModalController, Translate } from '@singletons';
import { CoreMath } from '@singletons/math';
import { Swiper } from 'swiper';
import { SwiperOptions } from 'swiper/types';
import { CoreSwiper } from '@singletons/swiper';
import { SafeResourceUrl } from '@angular/platform-browser';

/**
* Modal component to view an image.
Expand Down Expand Up @@ -52,6 +53,8 @@ export class CoreViewerImageComponent implements OnInit {
@Input() component?: string; // Component to use in external-content.
@Input() componentId?: string | number; // Component ID to use in external-content.

dataUrl?: SafeResourceUrl;

private static readonly MAX_RATIO = 8;
private static readonly MIN_RATIO = 0.5;

Expand All @@ -72,6 +75,12 @@ export class CoreViewerImageComponent implements OnInit {
*/
ngOnInit(): void {
this.title = this.title || Translate.instant('core.imageviewer');

if (this.image.startsWith('data:')) {
// It's a data image, sanitize it so it can be rendered.
// Don't sanitize other images because they load fine and they need to be treated by core-external-content.
this.dataUrl = DomSanitizer.bypassSecurityTrustResourceUrl(this.image);
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/core/singletons/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,22 @@ export class CorePath {
}
}

/**
* Check if a certain path is the ancestor of another path.
*
* @param ancestorPath Ancestor path.
* @param path Path to check.
* @returns Whether the path is an ancestor of the other path.
*/
static pathIsAncestor(ancestorPath: string, path: string): boolean {
const ancestorSplit = CoreText.removeEndingSlash(ancestorPath).split('/');
const pathSplit = CoreText.removeEndingSlash(path).split('/');

if (ancestorSplit.length >= pathSplit.length) {
return false;
}

return !ancestorSplit.some((value, index) => value !== pathSplit[index]);
}

}
9 changes: 9 additions & 0 deletions src/core/singletons/tests/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ describe('CorePath', () => {
expect(CorePath.concatenatePaths('foo/bar', 'baz')).toEqual('foo/bar/baz');
});

it('checks ancestor paths', () => {
expect(CorePath.pathIsAncestor('/foo', '/foo/bar')).toEqual(true);
expect(CorePath.pathIsAncestor('/foo/', '/foo/bar')).toEqual(true);
expect(CorePath.pathIsAncestor('/foo', '/foo/bar/baz')).toEqual(true);
expect(CorePath.pathIsAncestor('/foo/baz', '/foo/bar')).toEqual(false);
expect(CorePath.pathIsAncestor('/foo/bar', '/foo/bar')).toEqual(false);
expect(CorePath.pathIsAncestor('/foo/b', '/foo/bar')).toEqual(false);
});

});

0 comments on commit e8457e8

Please sign in to comment.