In SwiftUI the scrollview inner UI View's shadow will be cut off by the size of scrollview? - scrollview

After updating the Xcode11 beta3, I found the scrollview inner view's shadow will be cut off at the bound, but it ok in the Xcode11 beta2. I just use the bottom padding for fixing it, but I don't think it's a good solution. Is there any other solutions to fix the problem?
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 30) {
ForEach(courses) { item in
PresentationLink(destination: ContentView()) {
CourseView(
title: item.title,
image: item.image,
color: item.color,
shadowColor: item.shadowColor
)
}
}
}
.padding(.leading, 40)
.padding(.bottom, 60)
the CourseView() has a shadow modifier, the definition's body just like:
var body: some View {
return VStack(alignment: .leading) {
Text(title)
.font(.title)
.fontWeight(.bold)
.color(.white)
.padding(30)
.lineLimit(4)
.padding(.trailing, 50)
Spacer()
Image(image)
.resizable()
.renderingMode(.original)
.aspectRatio(contentMode: .fit)
.frame(width: 246, height: 150)
.padding(.bottom, 30)
}
.background(color)
.cornerRadius(30)
.frame(width: 246, height: 360)
.shadow(color: shadowColor, radius: 20, x:0, y: 20)
}
I hope the CourseView()'s shadow could display OK, not be cut off by the bound of ScrollView.

Try to use Spacer() after and before your horizontal stack. This way your horizontal stack (HStack) will take full height of your scroll view. Hope it helps

I have a workaround for you issue. The solution is use the offset in the next view and overlap it on top of the ScrollView. In your case it would look like something like this:
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 30) {
ForEach(courses) { item in
PresentationLink(destination: ContentView()) {
CourseView(
title: item.title,
image: item.image,
color: item.color,
shadowColor: item.shadowColor
)
}
}
}
.padding(.leading, 40)
.padding(.bottom, 60)
}
SomeView().offset(x:0, y: -60) // 60 is your bottom padding so we offset by negative 60 to counter it.

Related

How do i access the currentIndex from gridview in qml and update it on changed [In QML]

How can I get the currentIndex from the gridView and highlight it and update back the currentIndex once it's changed to another item? [IN QML]. Please let me know what is the solution.
Thank you in advance!
GridView{
id: colorGrid
model: colorModelData
delegate: ItemDelegate{
id: colorcomboDelegate
background: Rectangle {
id: colorRect
anchors.centerIn: parent
width: colorGrid.cellWidth * 0.6
height: colorGrid.cellWidth * 0.6
radius: width/2
color: colorModelData[index]
}
Rectangle {
id:colorSelectedRing
anchors.centerIn: parent
width: colorRect.width * 1.30
height: width
radius: width/2
z:-1
visible: index=== colorGrid.currentIndex? true:false [...ERROR]
Rectangle {
id:colorSelectedBlackRing
anchors.centerIn: parent
width: colorRect.width * 1.13
height: width
radius: width/2
}
}
}
currentIndex: [Need to update the current index]
}

How to pass an array of color for rectangle in qml

I want to pass the colorModelData for rectangle shown below.
Requirement is: on click of button i want to open a popup. And inside popup want to display multiple number of circles with different colors. Using button can i create a popup which will give me list of colors? ALso list of color should be exposed from outside.
How can i do it?
Rectangle {
id: control
property var colorModelData: ["Red", "Green", "Blue"]
Button{
id: btn
width: 100
height: 100
onClicked: {
rect.visible = true
}
}
Rectangle{
id: rect
visible: false
width: 400
height: 300
color: "gray"
anchors.top: btn.bottom
GridView{
width: rect.width
height: rect.height
model: colorModelData
delegate: Column{
Rectangle {
width: 20
height: 20
radius: width/2
//color: colorModelData [..... getting error]
}
}
}
}
}
I tested your code and it works for me. So I assume the only part you're missing is the line you have commented out. Use this:
color: colorModelData[index]

How to keep qml Rectangle border from overlapping contents?

I want a Rectangle to auto-size itself to fit exactly around its visual children. If there is no border, then the following works great:
Rectangle {
width: childrenRect.width+(border.width*2)
height: childrenRect.height+(border.width*2)
...
}
HOWEVER, if the Rectangle has a border, the children will overlap it. I tried unsuccessfully wrapping the children in a container (Column in the example below) and using anchor.margins to shift the container over to miss the Rectangle's borders.
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 600; height: 600
Rectangle {
id: rect
border.width : 20
border.color: "yellow"
clip: true
width: childrenRect.width+(border.width*2)
height: childrenRect.height+(border.width*2)
Column {
anchors.margins: rect.border.width // does not work
Text { height: 40; text: "FoooooooooooooooMumble" }
Text { height: 40; text: "Bar" }
Button { height: 40; text: "press me" }
}
}
}
Can someone suggest how to do this?
For anchors.margins to work, the border anchors must be set (the margin space is relative to those). For example:
Column {
anchors.margins: rect.border.width
anchors.left: rect.left
anchors.top: rect.top
...
}

Animating using NumberAnimation and Behavior

I'm trying to understand the functionality of Behavior by animating a small Rectangle when it's property changes.
Consider the following example:
import QtQuick 2.4
import QtQuick.Controls 1.2
Item {
width: 600
height: 80
Rectangle {
id: rect
color: "red"
width: 20
height: 20
property int xval: 0
Behavior on xval {
NumberAnimation {
target: rect
property: "x"
to: rect.xval
duration: 2000
easing.type: Easing.InOutQuad
}
}
}
Button {
anchors.bottom: parent.bottom
onClicked: { rect.xval=250 }
}
}
Here I'm trying to animate the x property of the Item rect on Button Click. But it doesnot animate. Now if you replace
to: rect.xval
with
to: 400
The Rectangle animates as expected on Button Click. All I want to do is to animate the Rectangle using the value set by the user. Am I missing something ?
You don't need a extra property to animate a property.
Behavior on foo will animate foo whenever it changes its value and make it the implicit property of inner Animations.
Your code can simply be
Item {
width: 600
height: 80
Rectangle {
id: rect
color: "red"
width: 20
height: 20
Behavior on x {
NumberAnimation {
duration: 2000
easing.type: Easing.InOutQuad
}
}
}
Button {
anchors.bottom: parent.bottom
onClicked: { rect.x=250 }
}
}

How can I get my title and my bottom to show in Titanium?

var galWin = Ti.UI.createWindow({
title: "Alejandro's Big Adventure",
modal: true,
backgroundColor: "828F99",
layout: "horizontal"
});
var border = Ti.UI.createView({
backgroundColor: "2585CC",
height: 1,
width: pWidth,
top: 30
});
var bottomButton = Ti.UI.createView({
backgroundColor: "828F99",
height: "10%",
width: pWidth,
bottom: 0
});
var galContainer = Ti.UI.createScrollView({
top: 0,
width: pWidth,
height: pHeight - border.height - border.top,
backgroundColor: "2585CC",
layout: "horizontal",
contentWidth: pWidth,
showVerticalScrollIndicator: true
});
for(var i = 0; i < myImages.length; i++){
var view = Ti.UI.createView({
borderRadius: 10,
top: margin,
left: margin,
width: size,
height: size
});
var img = Ti.UI.createImageView({
image: "images/" + myImages[i],
top: 0,
width: view.width * 1.25,
height: view.height * 2
});
view.add(img);
galContainer.add(view);
};
Firstly: for the title if you want to get the title of the window
so you can get it with getTitle() method like this
galWin.getTitle()
secondly: for the bottom
if you want to get the bottom of the window here you can't do that because the window is the top element in you hierarchy and is the doc
Window's bottom position, in platform-specific units.
On Android, this property only works with lightweight windows. See "Android Heavyweight and Lightweight Windows" in the main description of Titanium.UI.Window for more information.
so you get the bottom of the element according to it's parent so here the window have no parent
but in general if you want to get the bottom of any element
you can use getBottom() but be aware that this method will return a number only if you provide a bottom property inside the element other than that you will get Nan
and if you want to get the bottom of an element after the layout drawn on the screen you can you postlayout event and using rect.y to get the top of the element and then you can add the element height and finally minus it from the window height and for that if you don't have the window height you can use displayCaps.contentHeight to get the screen height
sorry for Long hope it help