wtorek, 22 listopada 2022

Nativescript close application

 Example of use in function onClose()

import { isIOS } from '@nativescript/core/platform';

//declaration of native functions
declare const android:any;
declare const exit: (code: number)=>void;

 

//Use for example in component 

onClose() {

    if (isIOS) {
        exit(0);
    } else {    
        android.os.Process.killProcess(android.os.Process.myPid());
    }
  }

Nativescript block Back Button on Android

 Example of blocking Soft Back Button on android in angular component

import { Component, OnInit } from '@angular/core';
import { isAndroid } from '@nativescript/core/platform';
import { AndroidApplication, AndroidActivityBackPressedEventData } from "@nativescript/core/application";
import * as app from "@nativescript/core/application";

declare const android:any;

//Put this code in implementation OnInit of component

ngOnInit() {   
     if (isAndroid) {
      app.android.on(AndroidApplication.activityBackPressedEvent, (data: AndroidActivityBackPressedEventData) => {                      
          data.cancel = true; // prevents default back button behavior          
      });
    }
  }


środa, 9 listopada 2022

Nativescript: Assets Folder Not Including html,js, css files

In default options WebpackPlugin copy Images and fonts folder. 
If You need to copy for example assets folder with js, html etc. for webView You mast update
 
CopyWebpackPlugin in your webpack.config.js to include the asset folder

for 6.x version of nativescript |
new CopyWebpackPlugin([
 { from: "fonts/**" },
 { from: "**/*.jpg" },
 { from: "**/*.png" },
 { from: "assets/**" }, // Add your asset folder path like this
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),

for 7,8 version

webpack.Utils.addCopyRule('assets/**')