How can I automatically get size of backgroundImage and assign it to view width and height? In .tss file.
NOTE: In .tss file, not in .js file. (I know the code in .js file)
EDIT
view.xml
<View id="innerView">
<ImageView id="middleImage"/>
</View>
view.tss
"#innerView":{
zIndex: 2,
height: 'auto',
width: 'auto',
left: "10dp",
right: "10dp",
top: "10dp",
},"#middleImage":{
image: '/images/iconbg.png', // put your image path here
left: "10dp",
right: "10dp",
top: "10dp",
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
},
i want to get size of image (middleImage) and assign to the upper view (innerView) so that my view can adjust its size according to the image
I'm not sure if I understand your question but setting the width/height of #innerView to Ti.UI.SIZE would adjust the size to the #middleImage size. Make sure to remove left/right because you can't have both, either its the size of the middleImage or it will have the size of the screen width - 10dp*2
Well,I think there's no need for you to use two UI components solve your problem. Just one is enougth:
.xml
<View id='innerView'/>
.tss
"#innerView":{
top: '10dp',
width: 'Ti.UI.SIZE',
height: 'Ti.UI.SIZE',
zIndex: 2,
backgroundImage:'/images/iconbg.png' //put your image path here
}
Or try like this:
.xml
<ImageView id='middleImage'/>
.tss
"#middleImage":{
top: '10dp',
width: 'Ti.UI.SIZE',
height: 'Ti.UI.SIZE',
zIndex: 2,
image:'/images/iconbg.png' //put your image path here
}
If you really need two UI components, and set property Ti.UI.SIZE to both of them, there're maybe something looks strange. Because, you have to know that Ti.UI.SIZE is mean that the child-view like the ImageView you set in the father-view View should make it's width and height fill it's father; however, once you also set the property to the father View ,it's means the View should make it's width and height fill its father--maybe a Window, and then it's maybe will looks strange.
.xml
<View id="innerView">
<ImageView id="middleImage"/>
</View>
.tss
"#innerView":{
top: '10dp',
zIndex: 2,
width: 'Ti.UI.SIZE',
height: 'Ti.UI.SIZE'
}
"#middleImage":{
width: 'Ti.UI.SIZE',
height: 'Ti.UI.SIZE',
image: '/images/iconbg.png' //put your image path here
}
Related
At this moment the library https://www.npmjs.com/package/#miblanchard/react-native-slider does not have a solution to be able to change the height of the left and right track of the thumb.
How to implement it?
I found a workaround:
The container in which the Slider is should have overflow style: "hidden"
I use renderThumbComponent to display the thumb left line to the left
renderThumbComponent={() => (
<>
<View style={styles.thickerLine} />
<View style={styles.thumb} />
</>
)}
I set the style for thickerLine to be as long as possible, so that it goes beyond the container.
thickerLine: {
position: "absolute",
top: 8,
right: 0,
backgroundColor: "blue",
height: 4,
width: window.width,
},
Yes, I know it's wild, but it works!
Stack:
React Native
React Navigator
Core components only
I have this style on TabNavigator.tsx:
const styles = StyleSheet.create({
tabStyle: {
backgroundColor: colors.background,
borderTopLeftRadius: 40,
borderTopRightRadius: 40,
height: 80,
overflow: 'hidden',
// position: 'absolute', // needed to ensure the bar has a transparent background in the corners
},
})
I keep commented the position absolute, there is always a background behind the corners, making it looking weird when a component of another color scroll.
Here it is, colored in yellow for visibility:
If I un-comment position absolute, the content flow behind the tab bar, making it feel more natural.
But...
I need to add a bottom margin on each screen to compensate the space that the tab takes, or the content in the bottom is hidden.
There i feel that there should be a good practice or a known pattern, maybe a tested workaround, that would make my life easier. Do you have an idea?
Thanks
Ahh, it's simple, after going through trial and error I discovered that just add Border Radius to it and make sure barStyle has overflow hidden. Here I pasted the snippet for it.
barStyle:{
borderRadius:50,
backgroundColor:"orange",
position: 'absolute',
overflow:'hidden',
left: 0,
bottom: 0,
right: 0,
padding:5,
}
Thnx me later...
tabBarOptions={{
style: {
backgroundColor: 'green',
borderTopLeftRadius: 30,
borderTopRightRadius: 30,
overflow: "hidden",
},
}}
I'm trying to get a bottom to top white to transparent-white transition in my React Native screen using Expo Linear Gradients:
https://docs.expo.io/versions/latest/sdk/linear-gradient.html
I copied the second example and flipped it around, and made it white instead of black. But now the "transparent" the white is supposed to fade in to is darker that the white is, see below:
The transparent actually is see through so that's good but is there a way to give it a white hue?
Code here:
<LinearGradient
colors={[ 'transparent', 'rgba(255,255,255,0.8)']}
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
height: 200,
}}
/>
It's because transparent is equal to rgba(0,0,0,0)
Try using rgba(255,255,255,0) instead of transparent to get a white to white transition
The w3 spec defines transparent as transparent black as can be read here
I actually found my own answer. "transparent" apparently translates to black-transparent, to get white just specify an rgba() in the white channel like so:
<LinearGradient
colors={[ 'rgba(255,255,255,0)', 'rgba(255,255,255,1)']}
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
height: 80,
}}
/>
I wanna have a ScrollView above a map. The content of the ScrollView should start at 2/3 of the screen so I can see the markers on the map and use the map. But when I start dragging the scroll view it should use the whole height to scroll and not just the 1/3 where the ScrollView is.
I tried positioning with top which let me use the map but scrolling happened just inside the small area left. paddingTop has the desired effect but it didn't let me use the map of course.
How can I achieve what I want?
clubResultContainer: {
position: 'absolute',
top: 0,
paddingTop: (Dimensions.get('window').height / 3) * 2,
left: 0,
right: 0,
bottom: 0,
zIndex: 20,
backgroundColor: 'transparent',
},
try to add flexDirection: 'row' on your stylesheet
I have created custom check boxes in my application. I have no issue with check box and it's label if the label text is small. If the label text is large (more than a one line) the alignment is not showing properly.
Look at the above screenshot: the first option label text is "Please select the 2 primary reasons rating the program testing the program" and second option label text is "Question2". If the text in first label is small that is which fits in one line then the UI looks good. But If text is more than one line I am facing the above issue.
My code is as follows,
View:
<Label class="standardType1">Please select the 2 primary reasons rating the program?</Label>
<View class="checkBoxContainerView">
<Widget id="box1" src="checkbox" value="true"/>
<Label class="question1">Please select the 2 primary reasons rating the program testing the program</Label>
</View>
<View class="checkBoxContainerView">
<Widget id="box2" src="checkbox" value="true"/>
<Label class="question1">Question2</Label>
</View>
Style:
"#box1":
{
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
left:10
}
"#box2":
{
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
left:10
}
".question1":
{
top: 3,
left: 13,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: '#fff',
font:{
fontSize: 16,
fontWeight: 'normal'
}
}
".checkBoxContainerView":
{
left: 15,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
layout: 'horizontal'
}
Can any one help me with that? Even if label text is more than one line the height of the view should automatically increase and option should be view. Please help me.
After thinking a lot about your problem I experimented a little bit. I did not use the checkBox but tried to receive a proper alignment if the label is a multi-line label.
Xml:
<View id="temp" layout="horizontal" top="0" left="0">
<Label id="headline"/>
<Label id="description"/>
</View>
And my .tss:
"#headline": {
top: "0",
left: "0",
width: "50%",
text: "Headline",
font: {
fontSize: 20
}
}
"#description": {
left: "0",
width: "50%",
text: "Your long text here",
font: {
fontSize: 16
}
}
As you can see I did not specify any height or width for my container (not defined in the .tss but in the xml) and only set a width parameter for my labels. You should consider to use 10-20% for your checkBoxes and the rest for your label. Do not specify any height parameters since the system will do this automatically.