Expanding the canvas leads to the freezing of the Ionic app on the emulator

I'm currently working on developing an ionic app that includes the feature of allowing users to sign their name on a canvas. I am utilizing signature-pad.js from https://github.com/szimek/signature_pad to create this signature functionality.

Everything runs smoothly when testing the app on a browser.

https://i.sstatic.net/lldkp.png

However, when running the app on an Android emulator, it experiences freezing issues upon navigating to the signature page.

The code for the controller handling the signature page is as follows:

(function() {
angular.module('ValShip').controller('signatureCtrl', signatureCtrl);

signatureCtrl.$inject = ['$cordovaFileTransfer','$state', '$stateParams','$ionicPopup', '$log'];

function signatureCtrl($cordovaFileTransfer,$state, $stateParams, $ionicPopup, $log) {

    var vm = this;

    var wrapper = document.getElementById("signature-pad"),
    clearButton = wrapper.querySelector("[data-action=clear]"),
    saveButton = wrapper.querySelector("[data-action=save]"),
    canvas = wrapper.querySelector("canvas"),
    signaturePad;

    window.onresize = resizeCanvas;
    resizeCanvas();

    signaturePad = new SignaturePad(canvas);

    clearButton.addEventListener("click", function (event) {
        signaturePad.clear();
    });

    saveButton.addEventListener("click", function (event) {

        if (signaturePad.isEmpty()) {

            // notify the user that the signature is empty
            $ionicPopup.alert({
                title: 'Signature pad is empty.',
                template: 'Please provide signature first.'
            });

        } else {
            $log.debug('TODO: Send png.');


            // Destination URL 
            var url = "http://foo/upload/upload.php";

             //File for Upload
             var targetPath = signaturePad.toDataURL("image/png", 1.0);

             // File name only
             var filename = ""+$stateParams.id +".png";

             var options = {
              fileKey: "file",
              fileName: filename,
              chunkedMode: false,
              mimeType: "image/png",
              params : {'directory':'upload', 'fileName':filename}
          };

          $cordovaFileTransfer.upload(url, targetPath, options).then(function (result) {
              $log.debug("SUCCESS: " + JSON.stringify(result.response));
          }, function (err) {
              $log.debug("ERROR: " + JSON.stringify(err));
          }, function (progress) {
                  // PROGRESS HANDLING GOES HERE
              });


          signaturePad.clear();

            // notify the user that the signature is empty
            $ionicPopup.alert({
                title: 'Success!',
                template: 'Signature saved.'
            });

            $state.go("app.master-bill", {id: $stateParams.id});
        }
    });

    //PROBLEM IS SOMEWHERE IN HERE!!!!
    function resizeCanvas(){
        var ratio = Math.max(window.devicePixelRatio || 1, 1);
        canvas.width = canvas.offsetWidth * ratio;
        canvas.height = canvas.offsetHeight * ratio;
        canvas.getContext("2d").scale(ratio, ratio);
    }

};
})();

It's evident that the issue lies within the resizeCanvas() function since removing it resolves the freezing problem but distorts the appearance of the drawn signature. How can I modify the resizeCanvas function to resolve this? Thank you in advance.

Answer №1

After running tests on an actual device, I can confirm that the signature page is functioning correctly. However, I encountered freezing issues with the emulator. If anyone has a solution to this problem specifically for the emulator, please feel free to provide your insights.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Angular directives to pre-select a default option

I am currently working on a select HTML tag with two options, and I want to set the first option as the default choice. My select element includes Angular directives like ng-change and ng-model. I have attempted to achieve this by adding selected = "select ...

How can you generate a dynamic array using TypeScript?

I am facing a challenge with an array provided below. let arr = [{_firstName: "john", _lastName: "tom", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19173432970", _sport: "Soccer"}, {_firstName: "Jason", _lastName: "Deli", ...

What is the reason behind the animation being refreshed when using slideToggle() in jQuery?

Recently, I managed to position a fixed div at the bottom of the viewport to serve as a contact tab. When this tab is clicked, it smoothly triggers a panel to slide out, which is functioning correctly. However, I'm faced with the challenge of making ...

"Compilation error: 'not defined' is not recognized, 'no-undef

I am currently working on a login form that will fetch values from this API: However, the password field is currently empty, allowing any password to be accepted. This results in the error: Failed to compile 'userName' is not defined no-undef; ...

I successfully created a Chinese writing practice deck in Anki, which is functional on the desktop version but unfortunately not compatible with Ankidroid

While AnkiDesktop is functioning properly, there seems to be an issue with character encoding in Ankidroid. Despite trying numerous solutions, the problem persists. The character length displays correctly in Anki Desktop, but not in Ankidroid. For example ...

Do the values returned by window.screen.width and height represent CSS pixels or physical screen pixels?

After exploring the API named screen and visiting this documentation link, my initial anticipation was that I would receive information regarding actual screen size pixels. https://developer.mozilla.org/en-US/docs/Web/API/Screen/width https://i.sstatic.n ...

Unable to instantiate a class using a module in React

I am on a mission to combine Monaco editor and Convergence in order to create a collaborative editor. To achieve this goal, I am referencing the following repositories and examples: https://github.com/convergencelabs/monaco-collab-ext https://github.com/c ...

The query pertaining to Facebook redirect functionality

I have a Facebook ad with a URL encoded in it, and I need to extract the final destination URL that it redirects to using JavaScript in my Python program. The standard urllib2/mechanize methods don't work because of the JavaScript involved, and as a P ...

What is the best way to retrieve the value of the hidden fields once the radio button has been selected?

I am currently attempting to retrieve the value of the hidden input fields each time a radio button is clicked. The code provided shows a single div structure, but there are multiple divs with the same structure. While I have been able to successfully ca ...

Getting the result from a JavaScript request, whether it's synchronous or asynchronous

This code snippet involves a function that starts with a synchronous comparison test == 0. If the comparison is true, it returns one piece of content; however, if it's not, an asynchronous request is made. The goal here is for the latter part to retur ...

Ensuring the Persistence of Column State in Material-UI DataGrid/DataGridPro when Adjusting Visibility Using Column Toolbar

We have integrated MUI DataGrid into our React project. Currently, I am exploring options to save the state of columns after toggling their visibility using the DataGrid toolbar column menu. After each re-render, the column setup returns to its default st ...

Manipulate the contents of an HTML class using Javascript to substitute text with an empty string

Is there a way to create a JavaScript function that can remove text upon clicking from multiple HTML fields with the same class? I am facing an issue where my function is not clearing the data in the target field when "Yes" is selected in the trigger. Re ...

The useRoutes function is returning null despite the correct pathname being provided

Check out my React code snippet! I've got the Component nestled within a micro-frontend application, which is then brought into the main app using module federation. // embedded in my microfrontend. const path = '/another-component-path'; f ...

Executing a query with a `has many` relationship in MongoDB: Step-by-step guide

In my setup with Node, Express, and backbone, I am successfully retrieving records from MongoDB collections using simple queries. However, I am struggling to understand how to query more complex data, such as the one below: db.employees.aggregate( [ ...

Problems with Vuex getter reactivity when used in conjunction with Vue router

I've encountered an issue with my Vuex getter that fetches data for the current route and displays it in a Vuetify v-data-table. Everything works perfectly fine when the component is initially created. However, when I add a new entry to the data array ...

How can you update the background image of a particular div using the 'onclick' feature in React.JS?

Thank you for helping me out here. I'm currently working with ReactJS and facing a challenge where I need to change the background of a div from a color to a specific image URL upon clicking a button in a modal. Despite my efforts, I keep encountering ...

Managing checkbox validation in Formik with React and Material UI

I am currently working on implementing Checkbox validation for an "Accept Terms of Service" checkbox using React and Material UI. Here is what I have done so far: Validation Schema const validationSchema = yup.object().shape({ email: yup .string() ...

You can either use handleSubmit() as an onSubmit function or simply pass onSubmit as a prop

I attempted to integrate the redux form into my stepper component. Following a tutorial, I implemented async form from In the tutorial's demo, everything was working smoothly. However, upon clicking the sign-up button, I encountered an ...

Error: app.module.ts cannot locate specified pipe by name

Struggling with my Angular 2 app development journey, I encountered difficulties with the Pipe decorator. In Angular 1, accessing key values of data was a breeze, but this time around, the implementation using Pipe brought up some challenges. I found a tem ...

conditionally manipulate colspan attribute with AngularJS

Is there a way to dynamically change the value of the 'th' colspan attribute based on a condition in Angular? I have attempted the following code, but it doesn't seem to be working. Can someone point out what might be incorrect here? <t ...