Fredy
Fredy

Reputation: 2063

List inside ScrollView is not displayed on WatchOs

I have a list inside a scrollview and it is not displaying below the image and the buttons. I've also tried to put the list and other items inside of a VStack and that allows me to see one item of the list at the time opposed to scrolling past the Image and buttons to show the whole list.

    ScrollView{
        Image(uiImage: self.image)
            .resizable()
            .frame(width: 80, height: 80)
            .scaledToFit()

        Text("\(name)")
            .lineLimit(2)
        HStack{
            Button(action: {
                print("button1")
            }){
                Image(systemName: "pencil")
            }
            Button(action: {
                print("button 2")
            }){
                Image(systemName: "trash")

            }
        }
        List{
            ForEach(self.items, id: \.self) { item in
                VStack{
                    Text(item.name)
                        .font(.headline)
                        .lineLimit(1)

                    Text(item.subname)
                        .font(.subheadline)
                        .lineLimit(1)
                }
            }
        }
    }
    .navigationBarTitle(Text("Tittle"))
    .edgesIgnoringSafeArea(.bottom)

Ive also tried to add .frame( minHeight: 0, maxHeight: .infinity) to the list to force it to have its whole height and that did not work either. Any suggestions or might this be a swiftUI bug ?

EDIT

I just realized Im getting this error when scrolling:

APPNAME Watch Extension[336:60406] [detents] could not play detent NO, 2, Error Domain=NSOSStatusErrorDomain Code=-536870187 "(null)", (
        {
        Gain = "0.01799999922513962";
        OutputType = 0;
        SlotIndex = 4;
    },
        {
        Gain = "0.6000000238418579";
        OutputType = 1;
        SlotIndex = 5;
    }
)

Upvotes: 2

Views: 539

Answers (3)

Reinhard Männer
Reinhard Männer

Reputation: 15217

I got the same error with UIKit. The error message is related to haptic feedback, see here.
It says that a haptic feedback could not be played, probably type 2, i.e. directionDown, see here.
Since my code does not call play(_:), it must be called by watchOS itself.
The reason for the error might be very fast scrolling, which could result in too frequent calls to play(_:) that cannot be handled properly. The docs say:

Do not call this method multiple times in quick succession. If the haptic engine is already engaged when you call this method, the system stops the current feedback and imposes a minimum delay of 100 milliseconds before engaging the engine to generate the new feedback.

If this is really an effect of watchOS, I guess you cannot do anything to avoid the error.

Upvotes: 0

Pavlo Ignatov
Pavlo Ignatov

Reputation: 31

Indicate some height for your List like

 List{
      ForEach(self.items, id: \.self) { item in
          VStack{
              Text(item.name)
                   .font(.headline)
                   .lineLimit(1)

              Text(item.subname)
                   .font(.subheadline)
                   .lineLimit(1)
          }
      }
 }.frame(minHeight: 200, maxHeight: .infinity)

Upvotes: 2

leoMehlig
leoMehlig

Reputation: 330

Have you tried putting the List inside of a GeometryReader and setting the frame there?

Upvotes: 0

Related Questions