enrecipes/app/shared/mixins.ts

70 lines
2 KiB
TypeScript
Raw Permalink Normal View History

2021-05-25 14:32:53 +00:00
declare const android: any
2021-06-15 11:04:42 +00:00
import { CoreTypes } from '@nativescript/core'
import { localize } from '@nativescript/localize'
const Intl = require('nativescript-intl')
2021-05-25 14:32:53 +00:00
2021-06-15 11:04:42 +00:00
export const myMixin = {
2021-04-01 10:55:35 +00:00
methods: {
2021-06-18 12:52:03 +00:00
mLoad({ object }) {
2021-04-12 18:09:48 +00:00
object._dialogFragment
.getDialog()
.getWindow()
.setBackgroundDrawable(
new android.graphics.drawable.ColorDrawable(
android.graphics.Color.TRANSPARENT
)
)
2021-04-01 10:55:35 +00:00
},
2021-06-18 12:52:03 +00:00
animateBar(obj, x: number, y?: number) {
let c = CoreTypes.AnimationCurve
if (y) obj.translateY = 64
2021-06-15 11:04:42 +00:00
return obj.animate({
2021-06-18 12:52:03 +00:00
opacity: 1,
translate: { x: 0, y: x ? 0 : 64 },
2021-06-15 11:04:42 +00:00
duration: 200,
2021-06-18 12:52:03 +00:00
curve: x ? c.easeOut : c.easeIn,
2021-06-15 11:04:42 +00:00
})
},
totalTime(prepTime, cookTime) {
let t1 = prepTime.split(':')
let t2 = cookTime.split(':')
let minutes = parseInt(t1[1]) + parseInt(t2[1])
let m = minutes % 60
let h = parseInt(t1[0]) + parseInt(t2[0]) + Math.floor(minutes / 60)
let hr = localize('hr')
let min = localize('min')
let mins = h * 60 + m
2021-06-18 18:37:12 +00:00
h = h && this.localeN(h)
m = m && this.localeN(m)
2021-06-15 11:04:42 +00:00
return {
time: h ? (m ? `${h} ${hr} ${m} ${min}` : `${h} ${hr}`) : `${m} ${min}`,
duration: `${mins}`,
}
},
setGravity(args) {
;(args.object || args).android.setGravity(this.RTL ? 5 : 3)
},
2021-06-20 17:54:47 +00:00
centerLVH({ object }) {
object.android.setGravity(17)
},
centerLV({ object }) {
object.android.setGravity(16)
},
2021-06-18 18:37:12 +00:00
localeN(n) {
2021-06-18 12:52:03 +00:00
return new Intl.NumberFormat(null).format(Number(n))
},
touchFade(object, action) {
let c = object.className
object.className = action.match(/down|move/)
? !c.includes('fade')
? c + ' fade'
: c
: c.replace(/ fade/g, '')
},
swipeBack({ direction }, method) {
2021-06-18 18:37:12 +00:00
if (this.$store.state.edgeS)
2021-06-18 12:52:03 +00:00
if (direction == 1) method ? method(0) : this.$navigateBack()
2021-06-15 11:04:42 +00:00
},
2021-04-01 10:55:35 +00:00
},
}