How to use Titanium app.tss in classic mobile app - titanium

I want to create a stylesheets for my Titanium app.
I'm not using Alloy framework, so how i can use app.tss? in which directory i need to store it?
Thank you

You can't.
.tss files are features bring by Alloy. However, if you want to use custom styles, you may have a look to the applyProperties method.
You can maybe do some workaround like this :
http://tifiddle.com/e9b87d0f3debd5e4a7bab3beb03dbddd
// Create window object
var win = Ti.UI.createWindow(),
label = Ti.UI.createLabel();
// Create or import properties
var properties = {
window: {
backgroundColor: "#1DB7FF"
},
label: {
text: "I Love Titanium",
color: "#FFFFFF"
}
};
// Apply properties
win.applyProperties(properties.window);
label.applyProperties(properties.label);
// Build views and launch
win.add(label);
win.open();

You can use CommonJS to achieve this
resources/styles.js
exports.Window = {
backgroundColor: 'blue',
backgroundImage: '/images/homebg.png',
exitOnClose: true
};
exports.Label = {
color: 'gray',
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
backgroundColor: 'transparent',
font: {
fontFamily:'Helvetica',
fontSize: '12dp',
fontStyle: 'normal',
fontWeight: 'normal'
}
};
Usages
var homeWin = Ti.UI.createWindow(require('styles').Window);
You can also refer this

Related

Legend not displaying for vue.js project using Echarts

I am working on a vue.js project and I am using the v-charts plugin. I cannot get the legend to display for any of the line graphs I am producing. I am able to produce the appropriate chart with x-axis and y-axis labels and a title for the chart. I have tried altering a ton of different options for the legend. I have also imported the legend component for e-charts individually.
I have tried multiple different formatting options for the legend.I have started a new project without any styling and still no luck. I'm sure there's something simple going on with my options object but I cannot figure it out.
Has anybody else ever run into this and found a solution?
I have been using this site as a resource for years and never asked a question. I can't figure this one out.
The chart options bar is being set in a function and the data is represented appropriately on the graph. I just need to be able to display the legend.
Code snippets and screenshot of graph below:
<template>
<div class="standard_div">
<!-- Begin chart component of graph -->
<v-chart v-if="showChart" :options="chartOptionsBar"/>
<!-- End chart component-->
</div>
</template>
<script>
// Import a different instance ECharts into the .vue file.
import ECharts from 'vue-echarts';
import 'echarts/lib/component/legend'
import 'echarts/lib/component/title'
</script>
chartOptionsBar = {
xAxis: {
// The data for the series
data: this.xAxisSeries,
// Parameters for the x axis
name: this.x_axis,
nameLocation: 'middle',
nameTextStyle: {
padding: [20, 20, 20, 20],
fontWeight: 'bold',
}
},
yAxis: {
// Parameters for the x axis
name: this.y_axis,
nameLocation: 'middle',
nameTextStyle:{
padding: [25, 25, 25, 25],
fontWeight: 'bold',
}
},
series: [
{type: 'line', data: this.yAxisSeries},
],
legend:{
top: 'auto',
left: 'auto',
right: 'auto',
bottom: 'auto',
width: '50%',
orient: 'horizontal',
lineHeight: '56',
padding: 25,
type: 'plain',
zlevel: 20,
data: ["item0"]
},
title:{
show: true,
text: this.graphTitle,
x: 'center',
textStyle: {
fontSize: 20,
}
},
};
The link includes an image of the graph that was produced from the options bar above.
I had the same problem and importing the legend using
import 'echarts/lib/component/legend'
in my component worked for me!
Try to play with positioning props

How do you apply a custom font when using Stripe in Vue? vue-stripe-elements-plus

I'm using the vue-stripe-elements-plus NPM module and I can't see how to add a custom font?
This plugin uses the options you pass in to the first element you create for creating the VUE elements.
It passes the style object to the style option when Stripe creates elements.
It passes the elements property to Stripe's elements function.
In here you can add a CustomFontSource object.
Please note, as in this example, if you want to use a Google font, you have to go to the URL provided and grab the URL within the #fontface descriptors. You would probably be better of hosting the font yourself as I fear these URLs may change over time.
stripeOptions: {
elements: {
fonts: [{
family: 'Lexend Deca',
src: 'url(https://fonts.gstatic.com/s/lexenddeca/v1/K2F1fZFYk-dHSE0UPPuwQ5qnJy_YZ2ON.woff2)',
unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD',
style: 'normal',
weight: '400',
display: 'swap',
}],
},
style: {
base: {
color: 'red',
fontFamily: '"Lexend Deca", sans-serif',
fontSize: '18px',
fontWeight: '400',
fontSmoothing: 'antialiased',
},
},
},
Stripe components:
<card-number
:stripe="stripeId"
:options="stripeOptions"
/>
<card-expiry
:stripe="stripeId"
:options="stripeOptions"
/>
<card-cvc
:stripe="stripeId"
:options="stripeOptions"
/>

Including scss in react-native project?

Is there a way to work with scss files in react native application? I am just curious and don't have much knowledge in react-native application architecture, But was thinking of using my current project scss files to work with the new react-native-android project we are planning to build.
REACT NATIVE VERSION : "0.46.4"
REACT VERSION : "16.0.0-alpha.12"
BABEL-PRESET-REACT-NATIVE: "2.1.0"
UPDATE :
I searched a little found out css-to-react-native which kinda let me transform my css into react-native stylesheet object, kinda workaround for me.
Thanks.
TL;DR: Yes, you can.
https://github.com/kristerkari/react-native-sass-transformer
It takes scss like:
.myClass {
color: blue;
}
.myOtherClass {
color: red;
}
and converts it to
var styles = {
myClass: {
color: "blue"
},
myOtherClass: {
color: "red"
}
};
Easy peasy.
TL;DR: No you cannot.
In react-native we are using inline style, which you can attain using Stylesheet.create.
Why you cannot CSS like styling is, In react native there are no #id either .class, so you cannot apply the style into #id or .class like you usually do in css styling. And also there is no related style, like in css you can do .element1 > .element2.
I think most developer main reason to use scss are to use nested class definition. Such as below:
.element1 {
> .element2 {
...
}
}
And because no class like feature in react-native component, there such method could not be apply in react-native.
Example how to create style in:
const styles = StyleSheet.create({
bigblue: {
color: 'blue',
fontWeight: 'bold',
fontSize: 30,
},
red: {
color: 'red',
},
});

Is there a way of storing color hex codes in variables similar to SASS in React-Native?

I have colours in my React Native project and I was wondering if I can store the colours in variables similar to how you would using SASS - naming them and saving them in a separate file. Below is an example of my styles for some input fields.
module.exports = StyleSheet.create({
textInput:{
backgroundColor: '#fff',
color: '#666',
height: 60,
marginBottom: 20,
marginLeft: 20,
marginRight: 20,
paddingLeft: 10,
paddingRight: 10,
}
});
I want to know if I can do something similar to this (SASS):
$cornflower-blue: #6195ED; (with other colour variables in separate file)
article {
background-color: $cornflower-blue;
}
Thanks in advance.
You can literally use variables in JavaScript.
colors.js
export const cornFlowerBlue = '#6195ED';
when you want to use it
import {cornFlowerBlue} from './colors';
...
module.exports = StyleSheet.create({
article {
backgroundColor: cornFlowerBlue,
}
});
EDIT: $cornflower-blue will not work as a name because - is reserved for subtraction.
I can suggest you react-native-extended-stylesheet that supports global and local variables like SASS:
// app entry: set global variables
EStyleSheet.build({
textColor: '#0275d8'
});
// component: use global variables
const styles = EStyleSheet.create({
text: {
color: '$textColor'
}
});
I use a settings file where I import any constants across my app
'use strict';
var settings = {
siteURL: 'http://www.website.com',
green: '#80bc5a',
lightGreen: '#c0dead',
lightGrey: '#f1efeb',
darkGrey: '#54575a',
brown: '#867f75',
};
var settings = require('./Settings')
module.exports = settings;
var { siteURL, green } = settings

How to enable button focus on touchStart?

I have created a button, I need some response from button like, on touch of the button, the button focus should enable like change in background color. How can I do that?
My code is,
View:
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Style:
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
Controller:
$.proceedButton.addEventListener('touchstart', function() {
$.proceedButton.isFocused = true;
});
$.proceedButton.addEventListener('touchend', function() {
$.proceedButton.isFocused = false;
});
The above code is not working. Just I need to slight chage in background color while touch of the button.
Any solution!!
Use this property and pass colour code
backgroundSelectedColor : "RED"
focusable must be true for normal views.
for more you can refer this http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.Button-property-backgroundSelectedColor
I hope it may help you,
Alloy xml would be like this
<Button class="button" id="proceedButton" onClick="openQuestionnaire">Proceed</Button>
Then the button property would be like this
".button":{
width: '50%',
top: '25dp',
borderRadius: 8,
borderWidth: 1,
borderColor: '#808080',
backgroundSelectedColor : "red",
backgroundSelectedImage : "/my_image.png",
backgroundGradient: {
type: "linear",
startPoint: { x: "0%", y:"0%"},
endPoint: { x: "0%", y:"100%"},
colors: [
{ color: "#4F94CD", offset: 0.0 },
{ color: "#4F94CD", offset: 1.0 }
]
}
}
You can set your selected image or background color on touch focus.
You wont need the controller code you have written in the controller.
Also for some object you can also have selectedColor.
You can also set backgroundFocusedImage,
As #CodeForFun mentioned you can use backgroundSelectedColor property of button.
Also following are all the states which can be used by a button in Titanium.
Disabled : backgroundDisabledImage and backgroundDisabledColor
Normal : backgroundImage and backgroundColor
Focus : backgroundFocusedImage and backgroundFocusedColor
Selected : backgroundSelectedImage and backgroundSelectedColor
Hope this would be helpful.
Edit : An example of usage:
View :
<Button class="button" >Proceed</Button>
TSS :
".button":{
width: '50%',
top: '25dp',
backgroundSelectedColor : "#4F94CD" //usage
}