ProMotion Screen lag

101 Views Asked by At

I'm developing an app with a list of train stations and when you select a station from the list, there should be a view that shows more information.

For the list I'm using PM::TableScreen

In there I have this method that gets called when a user selects a station:

def select_station(station)
  open StationScreen.alloc.initWithStation(station)
end

And the corresponding StationScreen

class StationScreen < UIViewController

  def initWithStation(station)
    init.tap do
      @station = station
    end
  end

  def loadView
    self.title = @station[:name]
    @layout = StationLayout.new
    self.view = @layout.view
  end

end

This produces the following:

enter image description here

Effects are smooth when you click the back button.

Now, I wanted to switch to ProMotion::Screen

StationScreen becomes:

class StationScreen < PM::Screen

  attr_accessor :station

  def on_load
    self.title = @station[:name]
    @layout = StationLayout.new
    self.view = @layout.view
  end

end

And the select_station method:

def select_station(station)
  open StationScreen.new(station: station)
end

Now the back animation is very strange. Notice how the image is still displayed for a while, and then goes away.

enter image description here

What am I doing wrong and how implement it properly with ProMotion::Screen?

UPDATE 1: This fixed it. Examples for ProMotion are suggestion the wrong thing.

def load_view
  self.title = @station[:name]
  @layout = StationLayout.new
  self.view = @layout.view
end

Is this the right way to do it?

1

There are 1 best solutions below

0
On BEST ANSWER

After some experiments, I figured it out. There are more than one way to solve it:

1) With on_load. The key here is to tell the layout what the root view is. Then it can figure out correctly how to do the back animation properly. If you don't give it root, like I did in the beginning - back animation can break. (At least that's how I understood it).

def on_load
  @layout = StationLayout.new(root: self.view)
  @layout.build
end

2) With load_view. Here, for some reason, it works fine without specifying the root view. I guess it happens automatically when you assign self.view to layouts view.

def load_view
  @layout = StationLayout.new
  self.view = @layout.view
end

I ended up using on_load.