Weird toolbar with nested conditionals behavior
@Jake pointed out that the problem was caused by the 2 Text objects being stacked without a VStack
.
Adding a VStack
fixed the problem completely.
Custom Rating view with nested H and VStacks leads to weird frame
test this
struct RatingGraphView: View {
var ratings: [Ratings] = [
Ratings(ratingCount: 130, starCount: 5),
Ratings(ratingCount: 90, starCount: 4),
Ratings(ratingCount: 25, starCount: 3),
Ratings(ratingCount: 20, starCount: 2),
Ratings(ratingCount: 3, starCount: 1)
]
var body: some View {
VStack(spacing: 0){
ForEach(ratings){rating in
RatingView(rating: rating)
}
}
.frame(height: 100)
}
@ViewBuilder
func RatingView(rating: Ratings)->some View{
GeometryReader{proxy in
HStack {
HStack{
Spacer()
ForEach(1..<rating.starCount+1){ star in
Image(systemName: "star")
.resizable()
.aspectRatio(contentMode:.fit)
.frame(height:15)
.scaledToFit()
//.padding(.bottom)
}
}
.frame(width:proxy.size.width/2.5)
let size = proxy.size
RoundedRectangle(cornerRadius: 6)
.fill(Color.blue)
.frame(width: (rating.ratingCount / getMax()) * (proxy.size.width * 1.5/3), height: 15)
}
}
}
func getMax()->CGFloat{
let max = ratings.max { first, second in
return second.ratingCount > first.ratingCount
}
return max?.ratingCount ?? 0
}
}
watchOS multiple toolbar items
Ok, found it. Placing them in a Stack (V or H) works
.toolbar {
ToolbarGroup {
VStack {
Button("1") {
}
Button("2") {
}
}
}
}
SwiftUI Animation bug?
got the same behavior. The code works well if I remove the "withAnimation". Or put "items.removeAll()" outside the "withAnimation"
CollapsingToolbarLayout doesn't recognize scroll fling
I had exactly the same issue with CollapsingToolbarLayout with ImageView inside and NestedScrollView. The fling scroll stops when finger is released.
However, I've noticed something strange. If you start scrolling with your finger from a view with OnClickListener (e.g. Button), the fling scrolling works perfectly.
Thus I fixed it with a weird solution. Set OnClickListener (that does nothing) on the direct child of NestedScrollView. Then it works perfectly!
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Page Content -->
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Give the direct child (LinearLayout) an id and set OnClickListener in Activity
ViewGroup mContentContainer = (ViewGroup) findViewById(R.id.content_container);
mContentContainer.setOnClickListener(this);
@Override
public void onClick(View view) {
int viewId = view.getId();
}
Notes:
Tested using Support Design Library 25.0.1
CollapsingToolbarLayout with scrollFlags="scroll|enterAlwaysCollapsed"
Related Topics
How to Prevent SQL Injections with User-Search-Terms in Vapor 4 (Fluent 4)
Why Cannot Read The Receipt Data for On-Device Validation
Create Record Only If Parent Exists in Vapor Using Fluent
Mapview Shows White Overlay on Interaction
Extension for Average to Return Double from Numeric Generic
Swift: Object Instance by Name
Accessing "Self" in Initializing Closure
Swiftui JSON Won't Print Title in Scrollview Hstack (But Will in List)
Writing an Enum Case Check to a Bool Variable Without Equatable Conformance
How to Refer to a Global Type from Within a Class That Has a Nested Type with The Same Name
How to Set Default Clouse Param in View Method
Crashlytics Doesn't Work with Xcode 10 Beta
Reduce Float Precision Using Regexp in Swift
Wrong Image Orientation After Displaytransform Call
Testing a Class Which Preserves Its State in Private Variables
Prevent Retain Cycle in Swift Function Pointers
Calculate Range of String from Word to End of String in Swift