iOS Question Problem with Sleep in iPhone-X (simulator)

D

Deleted member 103

Guest
Hi,

with the iPhone-X (simulator), this code causes an error.
The iPhone 6+, iPad Mini and iPhone 6+ (simulator) it works without problems.
Now I do not know if the errors are only with the iPhone X (simulator) or also with the normal iPhone X.

Here is code:
B4X:
Private Sub FillCronoTimer(Timerlist As List, IsListChanged As Boolean)
    Dim racetime1 As RaceProperty
    Dim pnl As Panel
   
    ShowProgressBar(True, 0)
   
    For i = 0 To Timerlist.Size -1
        '...
        customlistview.Add(Timerlist.Get(i))
        '...
        ShowProgressBar(True, i / Timerlist.Size)
        Sleep(0)
        Log("Sleep=" & i)
    Next
    ColorAllPanel
   
    ShowProgressBar(False, 0)
End Sub

Private Sub ShowProgressBar(Visible As Boolean, Value As Double)
    pnlProgressBar.BringToFront
    pnlProgressBar.Visible = Visible
    lblProgress.Width = Value * (ProgressBar.Width - 2dip)
End Sub

Private Sub ColorAllPanel
    Log("ColorAllPanel")
    '...
End Sub

Here are the logs:
Logs in iPhone-x (Simulator)
Sleep=0
Sleep=1
Sleep=0
Sleep=2
Sleep=1
Sleep=3
Sleep=2
Sleep=4
Sleep=3
Sleep=5
ColorAllPanel
Sleep=4
Sleep=5
ColorAllPanel


Logs in iPhone 6+
Sleep=0
Sleep=1
Sleep=2
Sleep=3
Sleep=4
Sleep=5
ColorAllPanel


Logs in iPhone 6+ (Simulator)
Sleep=0
Sleep=1
Sleep=2
Sleep=3
Sleep=4
Sleep=5
ColorAllPanel
 
D

Deleted member 103

Guest
and here are the logs if you do not use Sleep (0), and that's how it should be.

B4X:
Private Sub FillCronoTimer(Timerlist As List, IsListChanged As Boolean)
    Dim racetime1 As RaceProperty
    Dim pnl As Panel
 
    ShowProgressBar(True, 0)
 
    For i = 0 To Timerlist.Size -1
        '...
        customlistview.Add(Timerlist.Get(i))
        '...
        ShowProgressBar(True, i / Timerlist.Size)
        'Sleep(0)
        Log("Sleep=" & i)
    Next
    ColorAllPanel
 
    ShowProgressBar(False, 0)
End Sub

Logs in iPhone-X (Simulator)
Sleep=0
Sleep=1
Sleep=2
Sleep=3
Sleep=4
Sleep=5
ColorAllPanel

I have to use the sleep function otherwise ShowProgressBar will not be displayed.
 
Upvote 0
D

Deleted member 103

Guest
Here again an example complete with project.
What I do not understand is why the event pnlRoot_Resize is always executed twice.
In this example, it becomes clear that if the Sleep function is used, then many more entries are added than it should be.
However, if the sleep function is deactivated, then almost all will be ok, unless the event pnlRoot_Resize is executed twice anyway.
How can you solve the problem?
Or am I basically doing something wrong? :(

In this example, of course, no sleep is needed because the entries are added very quickly, but in my case it is necessary to make the ShowProgressBar function visible.

Here are the logs:
iPhone 6+5 (Show.page1):

Application_Start
iPhone 6+5 (Show.page1):

pMain_Resize
pnlRoot_Resize Width = 736
pnlRoot_Resize Width = 736
Application_Active


iPhone 6+5 (Show.page2):

pPage2_Resize
pnlRoot_Resize Width = 736
Item 0
Item 1
pnlRoot_Resize Width = 736
Item 0
Item 2
Item 1
Item 3
Item 2
Item 4
Item 3
Item 5
Item 4
Item 6
Item 5
Item 7
Item 6
Item 8
Item 7
Item 9
Item 8
Item 10
Item 9
ColorAllPanel
Item 10
ColorAllPanel

#############################################

iPhone X (Show.page1):

Application_Start
Application_Active
pMain_Resize
pnlRoot_Resize Width = 812
pnlRoot_Resize Width = 724


***********************
iPhone X (Show.page2):

pPage2_Resize
pnlRoot_Resize Width = 812
Item 0
Item 1
pnlRoot_Resize Width = 724
Item 0
Item 2
Item 1
Item 3
Item 2
Item 4
Item 3
Item 5
Item 4
Item 6
Item 5
Item 7
Item 6
Item 8
Item 7
Item 9
Item 8
Item 10
Item 9
ColorAllPanel
Item 10
ColorAllPanel
 

Attachments

  • b4i-test.zip
    6.1 KB · Views: 263
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't assume that the resize event will be raised once. All kinds of things can cause it to be raised.

Why are you filling the items from the resize event? Fill the list when the page is created or shown. I recommend you to check this example as you are not creating the page correctly: https://www.b4x.com/android/forum/threads/48170/#content
 
Upvote 0
D

Deleted member 103

Guest
Don't assume that the resize event will be raised once. All kinds of things can cause it to be raised.
that causes me less problems.

The biggest problem is that the entries that are added are more than 10, and then not in the correct order.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The biggest problem is that the entries that are added are more than 10, and then not in the correct order.
It happens because there is an assumption that the resize event will only be raised once.

because when Page_Appear or Page.Show the size of pnlRoot is not correct.
A properly built layout, like the one in your app, will be resized properly.

1. Move FillCronoTimer to Show (which is broken as I previously wrote).
2. Increase the Sleep interval to 100 to make the progress more noticeable.
 
Upvote 0
D

Deleted member 103

Guest
A properly built layout, like the one in your app, will be resized properly.
The entries for the xCustomListView are all generated by code in runtime.

1. Move FillCronoTimer to Show (which is broken as I previously wrote).
if I do so, then the width of the panel for the first entry is larger than the others because the panel pnlRoot is not yet the right size.

2. Increase the Sleep interval to 100 to make the progress more noticeable.
I think that does not make sense, because the display of 100 entries was about 10 seconds.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The entries for the xCustomListView are all generated by code in runtime.
It doesn't matter.

if I do so, then the width of the panel for the first entry is larger than the others because the panel pnlRoot is not yet the right size.
I haven't noticed it. Test it.

I think that does not make sense, because the display of 100 entries was about 10 seconds.
I just change it to be able to see the progress effect. It was too fast without it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
D

Deleted member 103

Guest
I haven't noticed it. Test it.

here my previous logs:
iPhone X (Show.page2):

pPage2_Resize
pnlRoot_Resize Width = 812
Item 0
Item 1
pnlRoot_Resize Width = 724
Item 0
Item 2
...

If not then you should handle the resize event and resize all elements yourself.
I think I have to make a few changes. :(
 
Upvote 0
Top