Titanium controller has a height I can't seem to control - titanium

I created a controller for a button I want to reuse in my Titanium application. I use the createController in one of my windows and add it to the window. So far so good.
However, the button seems to be having a full window worth of height, and I can't find a way to change this. What am I missing? Below my files:
view button.xml:
<Alloy>
<View id="generalButtonContainer">
<View id="generalButton" class="generalButton" onClick="callback" >
<Label class="generalButtonLabel" id="generalButtonLabel" />
<ImageView class="generalButtonIcon" />
</View>
</View>
</Alloy>
button.tss:
".generalButton": {
height: 60,
borderRadius: 2,
backgroundColor: '#5ba7e6',
left: 10,
right: 10
}
".generalButtonLabel": {
color: '#ffffff',
font: {
fontSize: 16
},
left: 15
}
".generalButtonIcon": {
image: '/images/generic/arrow-thin-right-white.png',
height: 15,
width: 15,
top: 22,
right: 15
}
"#generalButtonContainer": {
width: 320,
height: Ti.UI.SIZE
}
And here I include it in my parent window
Alloy.createController('button',{text: 'signup.button.continue'});
$.signupButtonContainer.add(buttonView.getView());
And now, even though I specify a height, (also in the parent window on signupButtonContainer : Ti.UI.SIZE) I still get a full window height view.
How do I fix this problem?
edit: in case there is any info you're missing, just ask! Complicated question with lots of information

I don't see anything obvious. Debugging these layout issues can involve some trial and error. I'd suggest two tactics.
1) Check the generated code in Resources/platform/alloy/controllers/controller.js to see if there's something obvious there. Keep in mind the default heights/widths for the various layout components for those components you see without explicit values.
2) I would suggest you use LiveView or TiShadow so that you can see layout changes quickly. Then, start setting background colors of the various elements to obvious colors (strings like pink, orange, green, etc. work well) to see which is filling the screen.

Related

React native "react-native-dropdown-select-list" when dropdown is used it moves the items below down. how to stop that from happening

I am using the react-native-dropdown-select-list. When dropdown is used/opened the items below on screen are pushed down instead of the menu coming up above them and not moving the items down. How to stop this from happening?
increased and decreased the zIndex. It didn't work
You can do this by using the dropdownStyles prop to style the dropdown. Adding position: absolute makes sure the dropdown goes over the other elements and does not push them. Some additional styling to make it look as before and overlap the other components.
<SelectList
dropdownStyles={{
backgroundColor: "white",
position: "absolute",
top: 40,
width: "100%",
zIndex: 999,
}}
/>

React-Native wrong dimension length in Android?

I'm facing an issue where apparently, when using useWindowDimensions() on React-Native, the length of the shortest dimension is incorrect.
Minimum reproducible example: Create an app from scratch using npx react-native run-android and paste the following on App.js:
export default function App() {
return (
<View style={{flex: 1}}>
<View
style={{
height: 100,
width: 100,
backgroundColor: 'red',
position: 'absolute',
top: useWindowDimensions().height - 20,
}}>
</View>
</View>
);
}
Explanation: there's a red-colored view of size 100 x 100 positioned absolutely on the screen. By doing top: useWindowDimensions().height - 20, I'm telling the view to move all the way to the bottom, and just to "peek" 20 dps.
On portrait orientation, it works:
But on landscape, it doesn't work. The view doesn't peek from the bottom
In fact, the view is still hidden at the bottom. Subtracting 20 from the height of the screen was not enough. I played around and found that I need to subtract at least 28 to make it visible:
What's going on? I would have expected that useWindowDimensions().height returned 28 less than what it did. Is this a bug? Or am I missing/not considering something else?
Note: at the beginning I thought it could be because of Android's status bar or navigation/action bar. But that doesn't make sense...because IT WORKS with a Portrait Orientation.

How to center oversize font inside Text's bounding box?

I'm trying to create a simple Floating Action Bar button with a plus icon in it, and have had trouble true-centering the "plus" in some edge cases. I was just using '\uFF0B' in a <Text>, but tried to switch to react-native-vector-icons, only to discover that they too were using a font and not an image to back the <Icon> instances, and that my problems seem to persist.
Things are fine on most screens and devices but in some cases users are reporting the plus icon is not perfectly centered. I have a hypothesis that it may involve users' accessibility options increasing the font size in the app beyond size of the parent View. At any rate I can reproduce something like the screenshots folks are sharing with me by setting the fontSize greater than the lineHeight. Assuming that is the issue -
How do you center a single glyph within the view area of a <Text> (or <Icon>, since that derives from <Text>), even when the fontSize may be much larger than the <Text>'s lineHeight or even overall height?
In the below example, the "+" font size is exactly double the line-height, so the plus is centered smack dab on the upper-right corner of the view area, as though it were expecting to be in a box that was 112dp x 112dp; but I want it centered dead-center of the 56dp x 56dp box instead, with the arms of the plus cropped. No combination of style attributes seems to effect it, but rather just controls where the <Icon> positions within its parent.
Currently:
Normally:
For oversized font:
Code:
<View style={s.fabStyle}>
<TouchableOpacity onPress={()=>{this.onPlus()}}>
<Icon name="plus" style={s.fabText} />
</TouchableOpacity>
</View>
...
const s = StyleSheet.create({
fabStyle: {
position: 'absolute',
right: 16,
bottom: 16,
borderRadius: 28,
width: 56,
height: 56,
backgroundColor: styleConstants.color.primary,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
},
fabText: {
position: 'relative',
left: 0,
top: 0,
right: 0,
bottom: 0,
fontSize: 112,
color: '#fff',
textAlign: 'center',
lineHeight: 56,
width: 56,
height: 56,
},
});
This isn't an answer to the question itself, which still stands, but an answer to the underlying issue, in case somebody arrives here by Google search with a similar issue. In my case it was indeed the case that accessibility settings were causing font to be bigger than it was designed to be, thus triggering the above scenario. While I still don't know how to center the text adequately in this case, in my case the issue could be circumvented by making sure allowFontScaling=false for relevant Views holding text.

how to add shadow around the image in react-native

I need to add a shadow around the Image my image is a rectangular field and i need to add a shadow around that rectangular field
I want to do something like this: stackoverflow question
I wanted to know how to do this in react native that can be applicable for both android and ios
Shadow is only for iOS. For Android you need Elevation. You could do something like this. I use it currently and works fine:
elevationLow: {
...Platform.select({
ios: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
},
android: {
elevation: 5,
},
}),
},
Wrap your Image inside View (for semantic clarity) and then define following style rules to the View:
shadow: {
shadowColor: '#202020',
shadowOffset: {width: 0, height: 0},
shadowRadius: 5,
},
I made an example here: https://snack.expo.io/rJesdOgRZ. But atm "snack" is so freaking slow that it's difficult to check actual results. But at least the code is visible and works as a benchmark.
You can use shadow style props for your View to achieve this. You will want
shadowOffset = takes in height and (optional, i dont really like using it, but ) width values to move your shadow in those directions.
shadowColor = takes a colour, similar to backgroundColor, indicates colour of the shadow
shadowRadius = takes a value, will dictate how far out your shadow is from the View
shadowOpacity = value from 0 to 1, indicates how strong the shadow presence is.
Heres a quick example of something you probably want. This code will make a red circle, with a slight shadow visible at the bottom of the circle. This code is of course customizable.
<View style = {{
position: 'absolute', top: 50, left: 50,
backgroundColor: 'red', width: 100, height: 100, borderRadius: 50,
shadowColor: "black",
shadowOffset: { height: 2},
shadowOpacity: 0.3,
}}>
//CONTENT
</View>
Another easiest and the best option I came across is the use of react-native-shadow-2 along with react-native-svg. Here, we need to install react-native-svg since react-native-shadow-2 is dependant on react-native-svg.
Basic shadow
import { Shadow } from 'react-native-shadow-2';
export default const ImageWithShadow = () => {
<Shadow>
<Image style={styles.imageStyles} source={ImageSource} />
</Shadow>
}
Advance shadow styling
import { Shadow } from 'react-native-shadow-2';
export default const ImageWithShadow = () => {
<Shadow startColor='#00000020' distance=10 radius=5 size=20>
<Image style={styles.imageStyles} source={ImageSource} />
</Shadow>
}
As shown in the above sample code you have to just wrap all the content (image or text or View or any other react native component) that you need to add a shadow inside the tag. No need of doing any manual styling like in react native shadow options. If you browse their documentation you can find many props that you can effectively utilize to customize the shadow applied to the component.

Overflow hidden no having affect

I have a simple progress bar, it has a borderRadius and overflow set to hidden. I have a child of this, it has no borderRadius, and it is overflowing outside of the corners. Here is my markup:
<View style={style.progressbar}>
<View style={[style.progressbarfill, { width:'50%' }]} />
</View>
const style = {
progressbar: {
backgroundColor: '#ccc',
height: 25,
width: '90%',
borderRadius: 12,
overflow: 'hidden'
},
progressbarfill: {
backgroundColor: 'springgreen',
width: '10%',
height: '100%'
}
}
This is what it looks like:
I put arrows on where the green is covering the border. The green should not overflow outside the edges.
Does anyone know why this is?
Actually I'm testing it right now, seems to be working fine on iOS, but Android is the one having the issue with the overflow right now. It looks like that is still getting more support currently. A temporary fix, is to just add the same borderRadius on the progressbarfill.
Here is the issue on the React Native Docs:
The overflow style property defaults to hidden and cannot be changed
on Android This is a result of how Android rendering works. This
feature is not being worked on as it would be a significant
undertaking and there are many more important tasks.
Another issue with overflow: 'hidden' on Android: a view is not
clipped by the parent's borderRadius even if the parent has overflow:
'hidden' enabled – the corners of the inner view will be visible
outside of the rounded corners. This is only on Android; it works as
expected on iOS. See the corresponding issue.
I found that, in addition to overflow: 'hidden' needed on the parent, I also needed backgroundColor: 'transparent' added to the parent
Edit: I also found that sometimes testing this required a refresh of my app.