Appending rows to an existing table (titanium) - titanium-alloy

var row = Titanium.UI.createTableViewRow({
chatId : data.chat_id,
title: 'New Account ',
backgroundColor: '#FFFFFF',
selectedBackgroundColor : 'transparent',
selectionStyle : 'Titanium.UI.iPhone.TableViewCellSelectionStyle.NONE on createTableViewRow',
width : '100%',
height : '60'
});
$.tableview.appendRow = row;
doesn't seem to be working, despite following docs.
Cheers.

appendRow is a method not a property, so you have to change:
$.tableview.appendRow = row;
to:
$.tableview.appendRow(row);

Related

How to use #media to change width in prop styled components

I am not sure if what they called but I have a component which takes its style as an object with its props.
const PricingSection = ({
secDesc,
}) => {
return (
<Text
{...secDesc}
content={intl.formatMessage({ id: 'packages.description' })}
/>
);
};
PricingSection.propTypes = {
secDesc: PropTypes.object
};
PricingSection.defaultProps = {
secDesc: {
width: '50%',
m: 'auto',
textAlign: 'center',
pt: '20px',
color: '#6a7a8d',
lineHeight: '1.5rem',
},
}
I want to apply different witdh for mobile devices. I know how to use #media tag in css but I dont know where to write #media in this component or how achieve what I want.
Instead of passing style object, it would be better if you apply a class to the component for easy maintenance. It'll also solve your problem for width for different size devices as you can add media query for the class in its css file.
Another suggestion would be to use styled-components. They provide great support for adding media queries inside the component file.
Refer:styled-components
you can use 'react-device-detect' and pass the different width from parent component like this:
enter code here
import isMobile from 'react-device-detect'
secDesc: {
width: isMobile ? '50%' : 'your value',
m: 'auto',
textAlign: 'center',
pt: '20px',
color: '#6a7a8d',
lineHeight: '1.5rem',
}
< PricingSection
secDesc={secDesc}
/>

Change div's "perceived window width"

I want to make the content of a div respond to its size, much like if
it was an iframe, but I can't use one.
My intent is to make the content adapt as if it was in a real smaller
screen so the user can preview the div content on mobile devices.
The iframe works, but it breaks react's diff algorithm, so I can't change the frame contents using the parent props anymore.
So, I want to be able to resize a div which will make it's contents responde
to it's media queries like if they are on a smaller window.
const Index = ({format}) => {
const classes = useStyles ({format})
// if I use iframe instead of div, the breakpoints works,
// but it breaks a lot of app logic
return <div className={classes.root}>
<ChildrenToPerceiveBreakpoint/>
</div>
}
const useStyles = makeStyles(theme => ({
root: props => ({
overflow: props?.format ? 'auto' : 'visible',
maxWidth: props?.format === 'mobile'
? 'min(414px, 100%)'
: props?.format === 'tablet'
? 'min(768px, 100%)'
: '100%',
maxHeight: props?.format === 'mobile'
? 'min(736px, 100%)'
: props?.format === 'tablet'
? 'min(1024px, 100%)'
: '100%',
margin: '0% auto',
marginTop: props?.format === 'mobile'
&& theme.breakpoints.down('md')
? '5%'
: '0%',
}),
}))
I'm using material-ui and jss for the styling.
Thx!

CSS not updating on mobile

I'm creating a skills chart in a React component, where each bar starts with a short width and then it expands to a specified width after 0.5 second. The width is related to the skill level, defined in the following array:
const skills = [
{ skillName: 'JavaScript', level: 10, color: 'bca538' },
{ skillName: 'HTML', level: 9, color: 'af4336' },
{ skillName: 'CSS', level: 9, color: '2f81b7' },
]
The chart is represented in the following code:
<div className="chart__bars">
{skills.map((skill, index) => {
const { skillName, level, color } = skill
const { scale } = this.state
return (
<div
className={'chart__bars__item'}
key={skillName}
style={{
background: `#${color}`,
height: `${(100 / skills.length) * (index + 1)}%`,
width: `${scale ? level * 10 : 30}%`,
zIndex: skills.length - index,
}}
>
<h4
style={{
opacity: `${scale ? 1 : 0}`,
}}
>
{skillName}
</h4>
</div>
)
})}
</div>
After the component is mounted, it triggers a state change after 0.5 second, which should then expand each bar (logic for this is inside the style property in the code above). Here's the initial state:
state = {
scale: false,
}
And here's where I change it:
componentDidMount() {
setInterval(() => {
this.setState({ scale: true })
}, 500)
}
It works fine on the browser, but not on mobile. Using the devtools I can see the width being updated, but it won't expand. If I uncheck the tick box for the width, and then check it again, then the width expands (which should happen automatically).
The working example is on my website: https://marcelcruz.io.
Any thoughts would be much appreciated!
Thanks.

Unable to set value of a textfield because its not in scope

I have a panel where in I have a button in the header which helps me to add two textfields in that panel. Now when I click on this button it takes me to a popup form where the user enters the value of the two textfields it wants and then clicks on save button in the header of this popup panel.
The two textfields are added but the value is not set to the value which is entered in the popup form. I think the problem is with the scope. Kindly look at the following code and tell me how to resolve this issue.
xtype: "panel",
id: 'idFieldpanel',
...
header:{
titlePosition: 0,
items:[{
xtype:'button',
text: 'Add',
handler: function(){
var addidFieldPanel= new Ext.form.Panel({
id: 'newidFieldPanel',
width: 250,
height: 100,
floating: true,
closable : true,
layout : {
type : 'vbox',
align : 'stretch'
},
bodyPadding: 10,
items : [
{
xtype : 'textfield',
id : 'newidFieldname',
fieldLabel : 'Name',
name : 'newidFieldname',
flex : 1,
scope : this
},
{
xtype : 'textfield',
id : 'newidFielddataType',
fieldLabel : 'DataType',
name : 'newidFielddataType',
flex : 1,
scope : this
}
],
header : {
titlePosition : 1,
items : [{
xtype: 'button',
text: 'Save',
handler: function() {
ctr++; //this is used so that the id of the added fields do not match and hence they do not overlap
Ext.getCmp('idFieldpanel').add({
xtype:"container",
layout : {
type : 'hbox',
align : 'stretch'
},
defaults: {
bodyPadding: 10,
margin: '10 0 10 10'
},
items: [
{
xtype : 'textfield',
fieldLabel: 'Name',
id: 'idFieldName' + ctr,
name : 'Data',
margin:'0 10 10 0',
flex : 1,
height : 'auto'
},
{
xtype : 'textfield',
fieldLabel: 'Datatype',
name : 'Type',
id: 'idFielddataType' + ctr,
margin: '0 10 10 0',
flex : 1,
height : 'auto'
}
]
});
Ext.getCmp('idFieldName' + ctr).setValue(Ext.getCmp('newidFieldname').getValue());
Ext.getCmp('idFielddataType' + ctr).setValue(Ext.getCmp('newidFielddataType').getValue());
}
}]
}
})
addidFieldPanel.show();
}
}]
}
There are a few things that can help you out here, but first would be to not bother with tracking unique ID's across your components. Let ExtJS handle that for you. Also, removing the nested handlers will make your code a lot easier to read. I put together this fiddle that shows how you can do that.
By not using ID's you can grab reference to parent/child components with the up/down selectors similar to saveBtn.up('panel').
You can also add a form to your popup for easier selecting. Hope this helps to give you an idea of a better way to leverage the framework.

YUI - Set padding style to drag node

I'm trying to set padding style to my drag node. I can set background-color but not padding.
Y.DD.DDM.on('drag:start', function(e) {
var drag = e.target;
drag.get('dragNode').setStyles({
backgroundColor: drag.get('node').getStyle('backgroundColor'),
padding: drag.get('node').getStyle('padding')
});
});
What I'm doing wrong ?
As said here : http://yuilibrary.com/trac-archive/tickets/2528774.html
I have to request all attributes individually with getComputedStyle()
paddingTop: drag.get('node').getComputedStyle('paddingTop'),
paddingBottom: drag.get('node').getComputedStyle('paddingBottom'),
paddingRight: drag.get('node').getComputedStyle('paddingRight'),
paddingLeft: drag.get('node').getComputedStyle('paddingLeft')

Resources