Expo BarcodeScanner via Camera returning wrong bounds - reactjs

I have been attempting to utilize the barcode scanner via the Camera exported by expo-camera due to being able to freeze the scanner upon scanning a valid QRCode. The problem is, the bounds being returned for the scanned region are incorrect.
Here is my usage of the Camera component:
<Camera
flashMode={flashMode}
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
onBarCodeScanned={scannedRegion ? undefined : handleQRScanned}
style={{
width: "100%",
height: "100%",
}}
ref={(el) => setScanner(el)}
>
The handleQRScanned method is just logging the output.
And here is what the scanned object looks like:
{
"bounds": Object {
"origin": Object {
"x": 0.7085477709770203,
"y": 0.2856549024581909,
},
"size": Object {
"height": 0.41216737031936646,
"width": 0.23583674430847168,
},
},
"cornerPoints": Array [
Object {
"x": 0.7085477791037765,
"y": 0.6859185008442614,
},
Object {
"x": 0.9367770043059619,
"y": 0.69782228348775,
},
Object {
"x": 0.9443845063336068,
"y": 0.29520473921943935,
},
Object {
"x": 0.7161692883258375,
"y": 0.28565489300913066,
},
],
"data": "exp://192.168.1.4:19000",
"target": 5303,
"type": "org.iso.QRCode",
}
Also, when previously using the BarcodeScanner exported by expo-barcode-scanner directly, the bounds come out correct. Has anyone experienced this before?

I had the same issue, I solved it by multiplying bound values with screen height and width from Dimensions API. By this way, you can correctly localize barcodes in screen. Here is the code snippet. Height and width are inversely proportioned meaning that bounds.size.width actually corresponds to screen height and vice versa.
height: Number(bounds.size.width) * deviceHeight,
width: Number(bounds.size.height) * deviceWidth,
right: Number(bounds.origin.y) * deviceWidth,
top: Number(bounds.origin.x) * deviceHeight,

Related

AutoPage Alexa skill APL

I'm trying to create a slide show (2-3 images) using the Alexa authoring tool.I have managed to do this using the APL Pager which displays a series of components one at a time. The thing is that in order to switch from image A to image B..C I have to touch the screen and swipe left/right.
i want to make this happen automatically and have alexa swicth the images within a certain time, and it seems that this can be achieved using APL autopage but for some reason this is not working 😩
What I've done
Set up the APL using the APL pager
Added the auto page to the APL document
Component Id
duration
delay
After trying the simulation and directly in an echo show 5 it still only triggers when the display is touched.
Also tried:
Adding the standard command (auto pager) directly in the handler of alexa but same response.
Some doubts
Does it matter if i put the commands in the APLdocument.json[1] file or directly in the handler when i call .addDirective[2]..the only difference i see if i want the content or duration to be dynamic i should put it directly in the backend code(index.js) right?
[1]
{
"type": "APL",
"version": "1.4",
"settings": {},
"theme": "light",
"import": [],
"resources": [],
"styles": {},
"onMount": [],
"graphics": {},
"commands": [
{
"type": "AutoPage",
"componentId": "fisrtpager",
"duration": 1000,
"delay": 500
}
],
[2]
handlerInput.responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
token:'arrugas',
document: physiolift,
commands: [{
"type": "AutoPage",
"componentId": "fisrtpager",
"duration": 1000,
"delay": 500
}]
});
}
Expected outPut
Have Alexa (echo show 5) to display a series of images like a carousel (without the need to touch the screen)
My code
APL Document
{
"type":"APL",
"version":"1.4",
"settings":{
},
"theme":"light",
"import":[
],
"resources":[
],
"styles":{
},
"onMount":[
],
"graphics":{
},
"commands":[
{
"type":"AutoPage",
"componentId":"fisrtpager",
"duration":1000,
"delay":500
}
],
"layouts":{
},
"mainTemplate":{
"parameters":[
"payload"
],
"items":[
{
"type":"Pager",
"id":"fisrtpager",
"width":"100%",
"height":"100%",
"items":[
{
"type":"Image",
"width":"100%",
"height":"100%",
"scale":"best-fill",
"source":"https://dyl80ryjxr1ke.cloudfront.net/external_assets/hero_examples/hair_beach_v1785392215/original.jpeg",
"align":"center"
},
{
"type":"Image",
"width":"100%",
"height":"100%",
"source":"https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
"scale":"best-fill"
},
{
"type":"Text",
"text":"Just text content shown on page #3",
"textAlign":"center"
}
],
"navigation":"wrap"
}
]
}
}
index.js
// somewhere inside the intent im invoking
if (Alexa.getSupportedInterfaces(handlerInput.requestEnvelope)['Alexa.Presentation.APL']) {
// Create Render Directive.
handlerInput.responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
token:'arrugas',
document: require('./documents/ImageTest.json')
});
}
speakOutput += ' just saying somthing'
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('just saying something else')
.getResponse();
Just add the command in the "onMount" event handler. Here is the modified code which does exactly what you need:
{
"type": "APL",
"version": "1.4",
"settings": {},
"theme": "light",
"import": [],
"resources": [],
"styles": {},
"onMount": [],
"graphics": {},
"layouts": {},
"mainTemplate": {
"parameters": [
"payload"
],
"items": [
{
"type": "Pager",
"id": "fisrtpager",
"width": "100%",
"height": "100%",
"items": [
{
"type": "Image",
"width": "100%",
"height": "100%",
"scale": "best-fill",
"source": "https://dyl80ryjxr1ke.cloudfront.net/external_assets/hero_examples/hair_beach_v1785392215/original.jpeg",
"align": "center"
},
{
"type": "Image",
"width": "100%",
"height": "100%",
"source": "https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg",
"scale": "best-fill"
},
{
"type": "Text",
"text": "Just text content shown on page #3",
"textAlign": "center"
}
],
"navigation": "none",
"onMount": [{
"type": "AutoPage",
"componentId": "fisrtpager",
"duration": 1000,
"delay": 500
}]
}
]
}
}
to update dynamically this feature from your backend code you can do the following:
// check if device supports APL
if (Alexa.getSupportedInterfaces(handlerInput.requestEnvelope)['Alexa.Presentation.APL']) {
// Create Render Directive.
handlerInput.responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
token: "dialogManagementPagerDoc",
document: require('./PATH-TO/YOUR-APL-FILE.json')
})
.addDirective({
type: "Alexa.Presentation.APL.ExecuteCommands",
token: "dialogManagementPagerDoc",
commands: [
{
type: "AutoPage",
componentId: "YOUR_PAGER_ID",
delay: 1000,
duration: 5000
}
]
});
}

VictoryPie Custom Colors

I'm using VictoryPie to show my data, however, I want to be able to choose which color represents which section. Mainly because this is a pie chart of colors. I have seen a couple questions on StackOverflow asking something similar, but none of them fixed my problem.
My data object looks like:
[
{
"color": "#0000fe",
"x": "blue",
"y": 1
},
{
"color": "#fe00fe",
"x": "fuchsia",
"y": 2
},
{
"color": "#fefe00",
"x": "yellow",
"y": 8
},
{
"color": "#008000",
"x": "green",
"y": 20
}
]
And my code to render it is:
<VictoryPie
data={this.state.sets}
style={{
data: { fill: (d) => d.color }
}}
/>
My Pie currently looks entirely black, and I wanted to know if I was doing something wrong.
you're taking a color from the wrong place, try this:
<VictoryPie
data={this.state.sets}
style={{
data: { fill: (d) => d.datum.color }
}}
/>

Bar series not rendering correctly under label using the react-vis library

I'm running into a problem. The bar series is not coming right under it's label. I can't figure out what is going wrong.
Here is the code for it
const FlexibleXYPlot = makeWidthFlexible(XYPlot);
<FlexibleXYPlot height={graphContainer.height} margin={graphContainer.margin} xDistance={0} xType="ordinal">
<HorizontalGridLines />
<XAxis/>
<YAxis orientation="right" style={yAxisStyles} />
{ this.state.data.map((lineData, i) => (
<VerticalBarSeries
key={i}
data={lineData.timeline}
/>
)); }
</FlexibleXYPlot>
and the data is this
[
{
"timeline": [
{
"x": "dataA",
"y": 12.21
}
]
},
{
"timeline": [
{
"x": "dataB",
"y": 21.09
}
]
},
{
"timeline": [
{
"x": "dataC",
"y": 16.66
}
]
}
I figured it out.
For each bar I was creating a separate series. I just had to pass the whole data to a single series. Now if somebody wants each bar to have a different color in a single series they can pass the color with the data like given below
[
{
"x": "dataA",
"y": 12.21,
"color": <something>
},
{
"x": "dataB",
"y": 21.09,
"color": <something>
},
{
"x": "dataC",
"y": 16.66,
"color": <something>
}
]
and we need to pass colorType="literal" to the series itself.

Display JSON data array from settings_data.json in page template liquid (Shopify)

My setting_data.json (Deput Shopify Theme)file:
{
"current": {
"checkout_error_color": "#ff6d6d",
"sections": {
"header": {
"type": "header",
"settings": {
"align_logo": "left",
"logo": "shopify:\/\/shop_images\/logo_9bb43dd5-21d6-442c-8a19-0f4adf03e13a.png",
"logo_max_width": 100,
"main_linklist": "main-menu",
"message": true,
"home_page_only": true,
"message_text": "Paw Paper – Edible Gift Wrap for Pets",
"message_link": "",
"color_bg": "#162950",
"color_text": "#ffffff"
}
},
How I can get section header variables in Shopify liquid template page?
I can get one variable:
{% assign text_color = settings.color_text %}
{{ text_color }}
I need to show custom block on page and get data for it from settings_data.json
"1543393771012": {
"type": "custom-content",
"blocks": {
"1543393771012-1": {
"type": "image",
"settings": {
"image": "shopify:\/\/shop_images\/info.png",
"width": "50%",
"alignment": "center"
}
},
"1543393802354": {
"type": "html",
"settings": {
"code": "<p>Paw Paper is the world's first edible wrapping paper designed specifically for pets. Our edible paper is 100% all-natural, made from potato starch with Omega-3 enhanced beef flavoring. It's water-soluble so no tape required!<\/p> <p>Just lick it like a stamp or dab water on the edges to bind the seams.<\/p>",
"width": "50%"
}
}
},
But, I can not get and display array with variables.
Help, please.
The settings_data.json file isn't something you can access directly in Liquid - but you can access the values stored within using the appropriate Liquid commands.
The global settings object in Liquid gives you access to all the variables defined in your settings_schema.json file, and nothing more.
However, your color_text setting isn't a theme setting, it's a section setting for the section named 'header'. This variable can be accessed as section.settings.color_text, so long as you are calling that from inside your header section.
Block settings are accessed in a similar way. Assuming that you have some sort of for block in section.blocks loop, those block-level settings can be accessed as block.settings.whatever_key_you_made
Remember - all of the settings you create have a corresponding scope and need to be accessed appropriately! settings_schema.json gives you your global settings object; each section has its private settings object; and each block has it's own personal settings object.
Hope this helps!
Assuming your JSONOBJ is correct.
var JSONOBJ={
"current": {
"checkout_error_color": "#ff6d6d",
"sections": {
"header": {
"type": "header",
"settings": {
"align_logo": "left",
"logo": "shopify:\/\/shop_images\/logo_9bb43dd5-21d6-442c-8a19-0f4adf03e13a.png",
"logo_max_width": 100,
"main_linklist": "main-menu",
"message": true,
"home_page_only": true,
"message_text": "Paw Paper – Edible Gift Wrap for Pets",
"message_link": "",
"color_bg": "#162950",
"color_text": "#ffffff"
}
}}}}
console.log(JSONOBJ.current.sections.header.settings.message_text)

How to shift object in Immutable Js Ordered map.?

I am working with redux, configured state as Immutable Js Ordered Map.
Below is the state:
{
"layers": {
"items": {
"yrgroih9": {
"width": '300px',
"x": '700px',
"y": '700px'
},
"qhy0dukj": {
"width": '160px',
"x": '500px',
"y": '500px'
},
"7lw2nvma": { //Target object
"width": '250px',
"x": '300px',
"y": '300px'
},
"jdkhsd9d": {
"width": '280px',
"x": '100px',
"y": '100px'
}
}
}
}
I want to shift the key 7lw2nvma one step up, & below is i want:
{
"layers": {
"items": {
"yrgroih9": {
"width": '300px',
"x": '700px',
"y": '700px'
},
"7lw2nvma": { //Shifted object
"width": '250px',
"x": '300px',
"y": '300px'
},
"qhy0dukj": {
"width": '160px',
"x": '500px',
"y": '500px'
},
"jdkhsd9d": {
"width": '280px',
"x": '100px',
"y": '100px'
}
}
}
}
Reducer code:
import { OrderedMap, fromJS } from 'immutable';
export default function myApp(state = new OrderedMap, action) {
switch (action.type) {
case 'SHIFT_OBJECT':
var shiftObj = "7lw2nvma"; //Known value
//return state.getIn(["layers","items"]).shift(shiftObj); // Something like this to shift object.
}
}
Help me to get the desired output.
Note: If it is not possible in OrderedMap, then say with List.
I found answer based on sortBy function in Immutable Js OrderedMap.
Now i added index values in that object as shown below:
{
"layers": {
"items": {
"yrgroih9": {
"index":0,
"width": '300px',
"x": '700px',
"y": '700px'
},
"qhy0dukj": { //Another known value
"index":1,
"width": '160px',
"x": '500px',
"y": '500px'
},
"7lw2nvma": { //Target object (shift up)
"index":2,
"width": '250px',
"x": '300px',
"y": '300px'
},
"jdkhsd9d": {
"index":3,
"width": '280px',
"x": '100px',
"y": '100px'
}
}
}
}
I have two known values 7lw2nvma & qhy0dukj.
Using setIn changed 7lw2nvma index as 1 & qhy0dukj index as 2.
Using sortBy function i can sort object based on modified index values.
var getSorted = state.getIn(["layers","items"]).sortBy(function(value, key) {
return value.get("index");
});
And now the state items sorted successfully.
You are trying to modify directly your state. That is forbidden for an immutable.
You can use Object.assign to create a new one.
return Object.assign({}, state.getIn(["layers","items"]).shift(shiftObj))
EDIT: You can use an array of your keys, sort it as you like and construct a new object for your state.
Something like:
let tab = Object.keys(state.getIn(["layers","items"]))
tab.sort() // sort keys by name
const obj = tab.reduce((o, key) => Object.assign(o, {[key]: state.getIn(["layers","items"])[key]}), {}) //contruct a new object from your ordered array and current state, you can also create another const on state.getIn(["layers","items"]) to increase perfs
console.log(obj)
return obj

Resources