Skip to content

Instantly share code, notes, and snippets.

@steveWinter
Created July 23, 2019 07:26
Show Gist options
  • Save steveWinter/6e014d4370dc1722ad17adf91938f869 to your computer and use it in GitHub Desktop.
Save steveWinter/6e014d4370dc1722ad17adf91938f869 to your computer and use it in GitHub Desktop.
Photo capture
This is part of a simple PoC app which amongst other things allows the user to take a photo and upload it to a remote API.
Everything works fine on Android, and has done on iOS until recent hardware which has resulted in odd aspect ratio images.
I understand this is a 'solved problem' based on https://github.com/NativeScript/NativeScript/pull/6127
The thing I don't understand is how to implement that fix into the code that I'm using - see image.js below.
For reference - in the app there's a button which has `tap="takePhoto"` which calls the below function.
I presume that I need to do something different at line 25 to implement the fix in the github link, but can't figure it out?
var camera = require("nativescript-camera");
var imageSource = require('tns-core-modules/image-source');
var FileMakerDataAPI = require('../shared/FileMakerDataAPI');
var ImageCaptureManager = require('../shared/ImageCaptureManager');
var view = require("tns-core-modules/ui/core/view");
let fmConnection = new FileMakerDataAPI({
'server': '',
'username': '',
'password': '',
'database': '',
});
let page;
let capture = new ImageCaptureManager(fmConnection, 'Images', page);
exports.takePhoto = function() {
page.bindingContext = { isLoading: true, progress: 0 };
capture.getLocation();
camera.requestPermissions();
camera.takePicture({saveToGallery: false})
.then(picture => {
imageSource.fromAsset(picture)
.then(image => {
// Update the UI
let imageContainer = view.getViewById(page, "img");
imageContainer.imageSource = image;
// Upload the image to the FM API
capture.saveAndUpload(image, page);
});
}).catch(function (err) {
console.log("Error -> " + err.message);
});
};
exports.onPageLoaded = function(args) {
page = args.object;
page.bindingContext = { isLoading: false, progress: 0 };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment