Skip to content

Commit

Permalink
chore: redirect to root
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-rosa-knowcode committed Dec 20, 2023
1 parent 671f541 commit 26d3468
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 46 deletions.
6 changes: 5 additions & 1 deletion Uno.Gallery/Uno.Gallery.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private Shell BuildShell(LaunchActivatedEventArgs e)
private bool IsThereSampleFilteredByArgs(MUXC.NavigationView nv, LaunchActivatedEventArgs e)
{
#if __WASM__
var argumentsHash = Uno.Gallery.Wasm.FragmentHavigationHandler.CurrentFragment;
var argumentsHash = Wasm.FragmentNavigationHandler.CurrentFragment;
#else
var argumentsHash = e.Arguments;
#endif
Expand All @@ -277,6 +277,10 @@ private bool IsThereSampleFilteredByArgs(MUXC.NavigationView nv, LaunchActivated
return true;
}
}
#if __WASM__
//If there is a Hash that is not valid, redirect it to the root of the site.
Wasm.LocationHrefNavigationHandler.CurrentLocationHref = "/";
#endif
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Uno.Gallery.Wasm
{
public class FragmentHavigationHandler
public class FragmentNavigationHandler
{
public static string CurrentFragment
{
get
{
const string command = "Uno.UI.FragmentNavigationHandler.getCurrentFragment()";
const string command = "Uno.Gallery.Wasm.FragmentNavigationHandler.getCurrentFragment()";
var fragment = WebAssemblyRuntime.InvokeJS(command);
return fragment;
}
Expand All @@ -17,7 +17,7 @@ public static string CurrentFragment
{
var escaped = WebAssemblyRuntime.EscapeJs(value);
var command =
"Uno.UI.FragmentNavigationHandler.setCurrentFragment(\"" + escaped + "\")";
"Uno.Gallery.Wasm.FragmentNavigationHandler.setCurrentFragment(\"" + escaped + "\")";

WebAssemblyRuntime.InvokeJS(command);
}
Expand Down
26 changes: 26 additions & 0 deletions Uno.Gallery/Uno.Gallery.Wasm/LocationHrefNavigationHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Uno.Foundation;

namespace Uno.Gallery.Wasm
{
public class LocationHrefNavigationHandler
{
public static string CurrentLocationHref
{
get
{
const string command = "Uno.Gallery.Wasm.LocationHrefNavigationHandler.getCurrentLocationHref()";
var locationHref = WebAssemblyRuntime.InvokeJS(command);
return locationHref;
}

set
{
var escaped = WebAssemblyRuntime.EscapeJs(value);
var command =
"Uno.Gallery.Wasm.LocationHrefNavigationHandler.setCurrentLocationHref(\"" + escaped + "\")";

WebAssemblyRuntime.InvokeJS(command);
}
}
}
}
3 changes: 2 additions & 1 deletion Uno.Gallery/Uno.Gallery.Wasm/Uno.Gallery.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
</ItemGroup>
<Import Project="..\Uno.Gallery.Shared\Uno.Gallery.Shared.projitems" Label="Shared" Condition="Exists('..\Uno.Gallery.Shared\Uno.Gallery.Shared.projitems')" />
<ItemGroup>
<_Globbed_Compile Remove="FragmentHavigationHandler.cs" />
<_Globbed_Compile Remove="FragmentNavigationHandler.cs" />
<_Globbed_Compile Remove="LocationHrefNavigationHandler.cs" />
</ItemGroup>
</Project>
14 changes: 13 additions & 1 deletion Uno.Gallery/Uno.Gallery.Wasm/WasmScripts/UnoGallery.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare namespace Uno.UI {
declare namespace Uno.Gallery.Wasm {
class FragmentNavigationHandler {
private static currentFragment;
static getCurrentFragment(): string;
Expand All @@ -17,3 +17,15 @@ declare namespace Uno.UI.Demo {
private static init;
}
}
declare namespace Uno.Gallery.Wasm {
class LocationHrefNavigationHandler {
private static currentLocationHref;
static getCurrentLocationHref(): string;
static setCurrentLocationHref(locationHref: string): string;
private static subscribed;
static subscribeToLocationHrefChanged(): string;
private static notifyLocationHrefChangedMethod;
private static notifyLocationHrefChanged;
private static initializeMethods;
}
}
127 changes: 89 additions & 38 deletions Uno.Gallery/Uno.Gallery.Wasm/WasmScripts/UnoGallery.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
var Uno;
(function (Uno) {
var UI;
(function (UI) {
class FragmentNavigationHandler {
static getCurrentFragment() {
return window.location.hash;
}
static setCurrentFragment(fragment) {
window.location.hash = fragment;
this.currentFragment = window.location.hash;
return "ok";
}
static subscribeToFragmentChanged() {
if (this.subscribed) {
return "already subscribed";
var Gallery;
(function (Gallery) {
var Wasm;
(function (Wasm) {
class FragmentNavigationHandler {
static getCurrentFragment() {
return window.location.hash;
}
this.subscribed = true;
this.currentFragment = this.getCurrentFragment();
window.addEventListener("hashchange", _ => this.notifyFragmentChanged(), false);
return "ok";
}
static notifyFragmentChanged() {
const newFragment = this.getCurrentFragment();
if (newFragment === this.currentFragment) {
return; // nothing to do
static setCurrentFragment(fragment) {
window.location.hash = fragment;
this.currentFragment = window.location.hash;
return "ok";
}
this.currentFragment = newFragment;
this.initializeMethods();
const newFragmentStr = MonoRuntime.mono_string(newFragment);
MonoRuntime.call_method(this.notifyFragmentChangedMethod, null, [newFragmentStr]);
}
static initializeMethods() {
if (this.notifyFragmentChangedMethod) {
return; // already initialized.
static subscribeToFragmentChanged() {
if (this.subscribed) {
return "already subscribed";
}
this.subscribed = true;
this.currentFragment = this.getCurrentFragment();
window.addEventListener("hashchange", _ => this.notifyFragmentChanged(), false);
return "ok";
}
static notifyFragmentChanged() {
const newFragment = this.getCurrentFragment();
if (newFragment === this.currentFragment) {
return; // nothing to do
}
this.currentFragment = newFragment;
this.initializeMethods();
const newFragmentStr = MonoRuntime.mono_string(newFragment);
MonoRuntime.call_method(this.notifyFragmentChangedMethod, null, [newFragmentStr]);
}
static initializeMethods() {
if (this.notifyFragmentChangedMethod) {
return; // already initialized.
}
const asm = MonoRuntime.assembly_load("Uno.Gallery.WASM");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "FragmentNavigationHandler");
this.notifyFragmentChangedMethod = MonoRuntime.find_method(handlerClass, "NotifyFragmentChanged", -1);
}
const asm = MonoRuntime.assembly_load("Uno.Gallery.WASM");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "FragmentHavigationHandler");
this.notifyFragmentChangedMethod = MonoRuntime.find_method(handlerClass, "NotifyFragmentChanged", -1);
}
}
FragmentNavigationHandler.subscribed = false;
UI.FragmentNavigationHandler = FragmentNavigationHandler;
})(UI = Uno.UI || (Uno.UI = {}));
FragmentNavigationHandler.subscribed = false;
Wasm.FragmentNavigationHandler = FragmentNavigationHandler;
})(Wasm = Gallery.Wasm || (Gallery.Wasm = {}));
})(Gallery = Uno.Gallery || (Uno.Gallery = {}));
})(Uno || (Uno = {}));
var Uno;
(function (Uno) {
Expand Down Expand Up @@ -93,3 +96,51 @@ var Uno;
})(Demo = UI.Demo || (UI.Demo = {}));
})(UI = Uno.UI || (Uno.UI = {}));
})(Uno || (Uno = {}));
var Uno;
(function (Uno) {
var Gallery;
(function (Gallery) {
var Wasm;
(function (Wasm) {
class LocationHrefNavigationHandler {
static getCurrentLocationHref() {
return window.location.href;
}
static setCurrentLocationHref(locationHref) {
window.location.href = locationHref;
this.currentLocationHref = window.location.href;
return "ok";
}
static subscribeToLocationHrefChanged() {
if (this.subscribed) {
return "already subscribed";
}
this.subscribed = true;
this.currentLocationHref = this.getCurrentLocationHref();
window.addEventListener("hashchange", _ => this.notifyLocationHrefChanged(), false);
return "ok";
}
static notifyLocationHrefChanged() {
const newLocationHref = this.getCurrentLocationHref();
if (newLocationHref === this.currentLocationHref) {
return; // nothing to do
}
this.currentLocationHref = newLocationHref;
this.initializeMethods();
const newLocationHrefStr = MonoRuntime.mono_string(newLocationHref);
MonoRuntime.call_method(this.notifyLocationHrefChangedMethod, null, [newLocationHrefStr]);
}
static initializeMethods() {
if (this.notifyLocationHrefChangedMethod) {
return; // already initialized.
}
const asm = MonoRuntime.assembly_load("Uno.Gallery.WASM");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "LocationHrefHavigationHandler");
this.notifyLocationHrefChangedMethod = MonoRuntime.find_method(handlerClass, "NotifyLocationHrefChanged", -1);
}
}
LocationHrefNavigationHandler.subscribed = false;
Wasm.LocationHrefNavigationHandler = LocationHrefNavigationHandler;
})(Wasm = Gallery.Wasm || (Gallery.Wasm = {}));
})(Gallery = Uno.Gallery || (Uno.Gallery = {}));
})(Uno || (Uno = {}));
4 changes: 2 additions & 2 deletions Uno.Gallery/Uno.Gallery.Wasm/ts/FragmentNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Uno.UI {
namespace Uno.Gallery.Wasm {
export class FragmentNavigationHandler {

private static currentFragment: string;
Expand Down Expand Up @@ -55,7 +55,7 @@
}

const asm = MonoRuntime.assembly_load("Uno.Gallery.WASM");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "FragmentHavigationHandler");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "FragmentNavigationHandler");
this.notifyFragmentChangedMethod = MonoRuntime.find_method(handlerClass, "NotifyFragmentChanged", -1);
}
}
Expand Down
64 changes: 64 additions & 0 deletions Uno.Gallery/Uno.Gallery.Wasm/ts/LocationHrefNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace Uno.Gallery.Wasm {
export class LocationHrefNavigationHandler {

private static currentLocationHref: string;

public static getCurrentLocationHref(): string {
return window.location.href;
}

public static setCurrentLocationHref(locationHref: string): string {
window.location.href = locationHref;
this.currentLocationHref = window.location.href;

return "ok";
}

private static subscribed: boolean = false;

public static subscribeToLocationHrefChanged(): string {

if (this.subscribed) {
return "already subscribed";
}

this.subscribed = true;

this.currentLocationHref = this.getCurrentLocationHref();

window.addEventListener(
"hashchange",
_ => this.notifyLocationHrefChanged(),
false);

return "ok";
}

private static notifyLocationHrefChangedMethod: any;

private static notifyLocationHrefChanged() {
const newLocationHref: string = this.getCurrentLocationHref();
if (newLocationHref === this.currentLocationHref) {
return; // nothing to do
}

this.currentLocationHref = newLocationHref;

this.initializeMethods();
const newLocationHrefStr = MonoRuntime.mono_string(newLocationHref);
MonoRuntime.call_method(this.notifyLocationHrefChangedMethod, null, [newLocationHrefStr]);
}

private static initializeMethods(): void {
if (this.notifyLocationHrefChangedMethod) {
return; // already initialized.
}

const asm = MonoRuntime.assembly_load("Uno.Gallery.WASM");
const handlerClass = MonoRuntime.find_class(asm, "Uno.UI.Wasm", "LocationHrefHavigationHandler");
this.notifyLocationHrefChangedMethod = MonoRuntime.find_method(handlerClass, "NotifyLocationHrefChanged", -1);
}
}

declare var MonoRuntime: any;
}

0 comments on commit 26d3468

Please sign in to comment.