I have managed to get it working via Stimulus and going to full screen is working well but for the life of me I can't work out how to exit full screen by clicking the same icon. I hope someone can help, thanks
import { Controller } from "#hotwired/stimulus"
export default class extends Controller {
static targets = ["fullScreen"]
connect() {
}
openFullscreen() {
if (!document.requestFullscreen) {
this.fullScreenTarget.requestFullscreen()
} else {
this.fullScreenTarget.exitFullscreen()
}
}
}
EDIT
perfect I followed the docs and added this, and it works well, is this ok? Thanks
openFullscreen() {
if (document.fullscreenElement) {
document.exitFullscreen()
} else {
this.fullScreenTarget.requestFullscreen();
}
}
}
Related
I know how to enter fullscreen once it's already loaded in a window. This causes an ugly effect where, when I click its icon, briefly flashes a windowed window which immediately goes fullscreen. I hate that effect.
How do I make it actually start, right away, in fullscreen, without ever being in windowed mode even for a split second?
You just need to put fullscreen: true in your manifest: https://docs.nwjs.io/en/latest/References/Manifest%20Format/#fullscreen.
If you want more info go to https://www.w3schools.com/howto/howto_js_fullscreen.asp#:~:text=To%20open%20an%20element%20in%20fullscreen%2C%20we%20use,fullscreen%20mode%20%28a%20video%20in%20this%20example%29%3A%20%2A%2F
this would work if youre making an website
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) { /* Safari */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE11 */
elem.msRequestFullscreen();
}
}
/* Close fullscreen */
function closeFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) { /* Safari */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE11 */
document.msExitFullscreen();
}
}
I'm not a JS pro but I code in python and i think if you made a function like this one it would work idk though
function onstart(){
if (boolean == true):
// Fullscreen code
}
// Your code here
onstart()
My project is built with master-detail navigation.
There are totally three pages in the list named as Resources, Contacts, and Login.
Everything works fine in iOS, but when the user presses the Droid/WinPhone devices hardware back button, the app should exit.
Is there any app-exit mechanism for Xamarin Forms which will work on all the devices.? (I mean native code not platform dependent)
Thanks in advance.
I did that on this way
In xamarin forms I added interface
public interface INativeHelper
{
void CloseApp();
}
In android project I made implementation of INativeHelper
public class NativeHelper : INativeHelper
{
public void CloseApp()
{
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
}
}
Implementation of INativeHelper in IOS
public class NativeHelper : INativeHelper
{
public void CloseApp()
{
Process.GetCurrentProcess().CloseMainWindow();
Process.GetCurrentProcess().Close();
}
}
And then just override method OnBackButtonPressed in page in Xamarin.Forms project
protected override bool OnBackButtonPressed()
{
INativeHelper nativeHelper = null;
nativeHelper = DependencyService.Get<INativeHelper>();
if (nativeHelper != null)
{
nativeHelper.CloseApp();
}
return base.OnBackButtonPressed();
}
I didn't made implementation for WinPhone, but it should be similar.
You can use a DepedencyService for closing an app when your physical back button is pressed:
In your UI (PCL), do the following:
protected override bool OnBackButtonPressed()
{
if (Device.OS == TargetPlatform.Android)
DependencyService.Get<IAndroidMethods>().CloseApp();
return base.OnBackButtonPressed();
}
Now implement the Android-specific logic in your Android project:
[assembly: Xamarin.Forms.Dependency(typeof(AndroidMethods))]
namespace Your.Namespace
{
public class AndroidMethods : IAndroidMethods
{
public void CloseApp()
{
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
}
}
}
Also create an Interface (in your UI PCL):
public interface IAndroidMethods
{
void CloseApp();
}
As far as I know there is no native way to exit the app in Xamarin application.
The only way is to use dependency service. Override OnBackButtonPressed function in your ContentPage and check it is the last page:
protected override bool OnBackButtonPressed()
{
if(navigation.NavigationStack.Count == 1)//navigation is MainPage.Navigation
DependencyService.Get<YourDependencyInterface>().CloseApp();
}
For Android in YourAndroidDependency class:
public void CloseApp()
{
(Xamarin.Forms.Forms.Context as Activity).Finish();
}
As for WinPhone I'm not sure but I believe it can be done in same way - dependency service.
Having experimented with all the above, I found that none of the above worked on a Google Pixel 3a, with latest version of Android
The command that came closest was
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
However it left the remains of the app still visible in the background.
The following worked for me when called from the Android Main Activity
public void ExitApp()
{
this.FinishAndRemoveTask();
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
}
The first line FinishAndRemoveTask removes the app from both the foreground and the background, however the Application process is still active, hence the need for the second command.
This is the more easy way found:
public void QuitApp(object sender, EventArgs args)
{
Process.GetCurrentProcess().CloseMainWindow();
Process.GetCurrentProcess().Close();
}
PS: Tested in android
You can use Environment.Exit(0);
I have twitter and facebook posting working in-game using Prime31's plugin. I'd like to be able to have a screenshot taken just as the user posts and uploaded with the post. This works using Application.CaptureScreenshot, but the first picture being taken was not being overwritten each time, and only the first picture taken was being used. To try and solve this I added the if statement in my "TakePicture()" method that checks if there is a picture at the filepath and deletes it if there is. This doesn't seem to be working though. I'm not sure why.
Any help would be much appreciated.
Thanks, Matt
void Awake()
{
pictureFilePath = Application.persistentDataPath + "/ScreenShot.png";
}
public void TakePicture()
{
Application.CaptureScreenshot(pictureFilePath);
}
public void PostToTwitter()
{
TakePicture ();
TwitterBinding.showTweetComposer("Test", pictureFilePath, "https://twitter.com/matski53");
}
public void PostToFacebook()
{
TakePicture ();
FacebookBinding.showFacebookComposer("Test", pictureFilePath, "https://twitter.com/matski53");
}
I would like to perform transactions only when webView is completely loaded.
I'm writing down the following code.
However, NSLog(#"completely loaded") is called several times.
- (void)webViewDidStartLoad:(UIWebView*)webView
{
self.webViewLoadingCount++;
}
- (void)webViewDidFinishLoad:(UIWebView*)webView
{
self.webViewLoadingCount--;
if (self.webViewLoadingCount > 0) {
// loading
return;
}
// completely loaded
NSLog(#"completely loaded");
}
Could you tell me how to solve this problem?
Thank you.
I need help detecting and dealing with the home button being pressed on a iPhone/iPod Touch running an AIR app. I tried
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
function handleKeys(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.HOME) {
//do something
}
}
without luck. Any ideas? Specifically, I want to prevent the app from closing when the home button is pressed.
import flash.events.Event;
addEventListener(Event.ACTIVATE, activateListener);
addEventListener(Event.DEACTIVATE, deactivateListener);
private function activateListener(e:Event):void{
//do something when awakened
}
private function deactivateListener(e:Event):void{
//do something when home button is pressed.
}