Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Adds react-native-windows UWP support #862

Merged
merged 4 commits into from
Dec 3, 2018

Conversation

rozele
Copy link
Collaborator

@rozele rozele commented Aug 29, 2017

This adds basic support for capturing photos and videos from either the front or back panel cameras, with some support for video quality, orientation, etc. This also uses ZXing.Net to support barcode scanning from the video preview frames. It also supports torch and flash modes. Videos and photos saved to disk (or camera roll / temporary folder) also supports some file metadata (e.g., lat/long).

There are a number of features that have not yet been implemented:

  • Support playSoundOnCapture for default shutter sounds
  • Add orientation metadata properties on photo / video files
  • Support all barcode formats in ZXing.Net
  • Additional file metadata (like description)
  • Photo quality settings with quality and jpegQuality
  • Image post-processing with mirrorImage and fixOrientation
  • Support event listeners for onZoomChanged & onFocusChanged
  • Device authorization checks as supported on iOS

"react-native": "~0.40.0",
"react-native-camera": "file:../"
"react-native-camera": "~0.10.1",
"react-native-windows": "^0.40.0"
Copy link
Collaborator Author

@rozele rozele Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset. #Closed

package.json Outdated
@@ -20,7 +20,8 @@
"barcode"
],
"dependencies": {
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react": "^15.4.0"
},
Copy link
Collaborator Author

@rozele rozele Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete #Closed

package.json Outdated
@@ -4,7 +4,7 @@
"type": "git",
"url": "https://github.com/lwansbrough/react-native-camera.git"
},
"version": "0.10.0",
"version": "0.10.1",
"description": "A Camera component for React Native. Also reads barcodes.",
Copy link
Collaborator Author

@rozele rozele Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset #Closed

mediaCapture.AudioDeviceController.Muted = options.Value<bool>("audio");

// TODO: test orientation
var orientation = options.ContainsKey("orientation") ? options.Value<int>("orientation") : cameraForView.Orientation;
Copy link
Collaborator Author

@rozele rozele Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete. #Closed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
this properties is null when i'm try to call the camera!! Can u help me??

@@ -6,8 +6,12 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "~15.4.0",
"react": "^15.4.0",
Copy link
Collaborator Author

@rozele rozele Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ [](start = 14, length = 1)

Reset. #Closed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi...Can you please share the steps to integrate this library in react-native-windows?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ptomasroos
Copy link
Collaborator

Just great @rozele ! Since I'm running vmware and windows from time to time I will def make sure to help out reviewing this!

@rt2zz
Copy link
Collaborator

rt2zz commented Aug 29, 2017

awesome! with the number of platform support inconsistencies across iOS, android and windows, I am thinking we are going to need a docs overhaul to better communicate what works where.

@ptomasroos ptomasroos self-assigned this Sep 8, 2017
@sm2017
Copy link

sm2017 commented Nov 10, 2017

@ptomasroos When you accept the PR?

@sibelius
Copy link
Collaborator

sibelius commented Jan 8, 2018

@rozele as I don't use windows much, I've added you as a contributor

so we can help us maintain this code, feel free to merge this if it is stable enough

@DavidRajPaul
Copy link

Hi...Can you please share the steps to integrate this library in react-native-windows?

@sibelius sibelius reopened this Mar 17, 2018
@DavidRajPaul
Copy link

Can i Just access RNCamera from react-native-camera for windows?

@DavidRajPaul
Copy link

I followed this code to implement barcode support in react-native-windows. But got this error when importing Camera. @rozele Can you please help?
capture

@DavidRajPaul
Copy link

Any updates??

@sibelius
Copy link
Collaborator

RNCamera is only for RN for now, u need to use RCTCamera on Windows

I don't like how to link this on windows

@DavidRajPaul
Copy link

Thanks for the update. Can anyone help me with linking with windows or suggest a plugin to implement barcode scan in windows? Any tutorial link or proper documentation? because the implementation steps mentioned are not clear and also very old.

@aliaksandr-kazarez
Copy link

Seems like this version won't work with react-native-windows above 0.52 because of System.Reactive.Linq dependency which has version 3.1.1, but react-native-windows updated to 4.0.0 preview in 0.53.

@sibelius
Copy link
Collaborator

@kozorezal can u try to update this branch to fix this? or send a new pr ?

This adds basic support for capturing photos and videos from either the front or back panel cameras, with some support for video quality, orientation, etc. This also uses ZXing.Net to support barcode scanning from the video preview frames. It also supports torch and flash modes. Videos and photos saved to disk (or camera roll / temporary folder) also supports some file metadata (e.g., lat/long).

There are a number of features that have not yet been implemented:
- Support `playSoundOnCapture` for default shutter sounds
- Add orientation metadata properties on photo / video files
- Support all barcode formats in ZXing.Net
- Additional file metadata (like description)
- Photo quality settings with `quality` and `jpegQuality`
- Image post-processing with `mirrorImage` and `fixOrientation`
- Support event listeners for `onZoomChanged` & `onFocusChanged`
- Device authorization checks as supported on iOS
@surajGoverdhanam
Copy link

Can anyone please provide documentation for react-native-camera windows support

@surajGoverdhanam
Copy link

I am getting "unable to get property 'Aspect ' of undefined or null".
I am using

"react-native": "0.54.0",
"react-native-camera": "^1.0.2",

@gtRfnkN
Copy link
Contributor

gtRfnkN commented Jul 26, 2018

@rozele, thank you very much for this effort - the library works really well on Windows and reads QR codes just fine! I'm running [email protected] & [email protected].

I am not sure, what is actually blocking this from being merged - can someone elaborate on that? I would love to help out with this PR, even though I have no experience with Windows programming, but I will try my best.

For everyone being stuck with the Aspect property bug: this should not happen if you're on the correct repository & branch and have set-up the library for windows correctly. Here is how you can do that:

  1. add the following dependency into you package.json:
    "react-native-camera": "https://github.com/rozele/react-native-camera/#windows",.
    This is the branch from @rozele with all the stuff RNWindows needs
  2. link the library as described here:
    https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md
    In the MainReactNativeHost.cs add using RNCamera; and new RNCameraPackage()
  3. add the camera & microphone capabilities to use the camera as described here:
    https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/simple-camera-preview-access#add-capability-declarations-to-the-app-manifest
  4. import and used as described in react-native-camera

PS: as @sibelius mentioned, you have to use RCTCamera not RNCamera (even though it's called RNCamera natively). So import like this: import Camera, { Barcode } from 'react-native-camera';

@sibelius
Copy link
Collaborator

Can we merge?

@gtRfnkN
Copy link
Contributor

gtRfnkN commented Jul 26, 2018

I would say not yet, I was too optimistic after it actually showed the camera stream and returned data for a QR code.

But the PR is still missing some things - here are two that I noticed already:

  • add to README how to set the library up with windows (a bit like what I wrote up there)
  • onBarCodeRead returns the data in a prop called text instead of data

I will try this library out some more and will also try to contribute as much as I can so we can get Windows supported 🙂

@expectpin
Copy link

@gtRfnk, on UWP app when I call takePictureAsync I get error '[JS Info] 'err: ', [TypeError: Object doesn't support property or method 'takePictureAsync']'.

`import Camera from 'react-native-camera';

takePicture = async () => {
try {
const data = await this.camera.takePictureAsync();
console.log('Path to image: ' + data.uri);
} catch (err) {
console.log('err: ', err);
}
};

render() {
return (

<Camera
ref={ref => {
this.camera = ref;
}}
style = {styles.preview}
permissionDialogTitle={'Permission to use camera'}
permissionDialogMessage={'We need your permission to use your camera phone'}
/>
<View style={{flex: 0, flexDirection: 'row', justifyContent: 'center',}}>

<Text style={{fontSize: 14}}> SNAP



);
}
}`

What I'm doing wrong?

@gtRfnkN
Copy link
Contributor

gtRfnkN commented Dec 3, 2018

@expectpin takePictureAsync is currently not implemented, you will have to use capture like this:

this.camera.capture({ target: 0 })
  .then(data => { ... })
  .catch(error => { ... });

@sibelius sibelius merged commit 1c62749 into react-native-camera:master Dec 3, 2018
@sibelius
Copy link
Collaborator

sibelius commented Dec 3, 2018

Open issues if something in this PR is not working well

We can improve it in another PRs

@n1ru4l
Copy link
Collaborator

n1ru4l commented Dec 5, 2018

🎉 This PR is included in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@n1ru4l n1ru4l added the released label Dec 5, 2018
@npmun
Copy link

npmun commented Jan 1, 2019

@gtRfnkN @expectpin any thoughts on what I am doing wrong here? I can't make react-native-camera work on UWP for some reason.
image

import React, { Component } from "react";
import { StyleSheet, Text, View } from "react-native";
import Camera from "react-native-camera";

export class CameraComp extends Component {
  _takePicture = async () => {
    if (this.camera) {
      const options = { quality: 0.5, base64: true };
      const data = await this.camera.takePictureAsync(options);
      console.log(data.uri);
    }
  };

  render() {
    return (
      <View style={styles.container}>
        <Camera
          ref={ref => {
            this.camera = ref;
          }}
          permissionDialogTitle={"Permission to use camera"}
          permissionDialogMessage={
            "We need your permission to use your camera phone"
          }
          style={styles.preview}
        >
          <View
            style={{ flex: 0, flexDirection: "row", justifyContent: "center" }}
          >
            <Text style={styles.capture} onPress={() => this._takePicture()}>
              [CAPTURE]
            </Text>
          </View>
        </Camera>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: "column",
    backgroundColor: "black"
  },
  preview: {
    flex: 1,
    justifyContent: "flex-end",
    alignItems: "center"
  },
  capture: {
    flex: 0,
    backgroundColor: "#fff",
    borderRadius: 5,
    padding: 15,
    paddingHorizontal: 20,
    alignSelf: "center",
    margin: 20
  }
});

thanks for your help!

@npmun
Copy link

npmun commented Jan 1, 2019

nevermind...looks like Camera cannot have any children.

@vikmis007
Copy link

@rozele Is there any further update in this? I want to scan a barcode that needs to be integrated into a UWP app.

@vikmis007
Copy link

@npmun Is the camera access working for you for UWP app?

@npmun
Copy link

npmun commented Sep 5, 2019

@vikmis007 Yes it does. But my use case is very basic.

@sibelius
Copy link
Collaborator

sibelius commented Sep 5, 2019

as RCTCamera was removed, you can send a PR renaming RCTCamera usage on UWP to RNCamera and it will probably work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.