infinitered / ProMotion-menu

RubyMotion gem allowing you to easily setup a facebook or Path style hidden slide menu easily with the ProMotion gem.
74 stars 29 forks source link

The side menu won't work if I opened the screen not from app_delegate #57

Closed poc7667 closed 5 years ago

poc7667 commented 9 years ago

THe side menu won't work on my webscreen from the fb_screen.

But it works if it opened from MenuDrawer on app_delegate

Appdelegate

    class AppDelegate < PM::Delegate
      def application(application, didFinishLaunchingWithOptions:launchOptions)

        @menu = open MenuDrawer

      end

menu dralwer

    class MenuDrawer < PM::Menu::Drawer
      def setup
        if User.already_exist? 
          self.center = WebScreen.new(url: SITE_URL)
        else
          self.center = FbScreen.new(nav_bar: false)
        end
        self.right = NavigationScreen
      end
    end  

FB screen

    class FbScreen < PM::Screen
        def load_webscreen
            open WebScreen.new(url: SITE_URL), left: NavigationScreen
        end
    end

NavigationScreen

        class NavigationScreen < ProMotion::TableScreen
          def table_data
            if User.already_exist?
              user = User.get
              params="user_id=#{user.id}&token=#{user.token}"
              [
                  {
                    title:  "   ",
                    cells: []
                  },
                  {
                    title:  "   ",
                    cells: [
                      {
                      title: 'Home',
                      action: :show_webpage,
                      arguments: SITE_URL
                      }
                    ]
                  }
              ]
            else
              [
                  {
                    title:  "   ",
                    cells: []
                  },
                  {
                    title:  "   ",
                    cells: [
                      {
                          title: 'Login',
                          action: :swap_center_controller,
                          arguments: FbScreen
                      }
                    ]
                  }
              ]
            end
          end

          def show_webpage(site_url)
            app_delegate.menu.center_controller = WebScreen.new(url: site_url, nav_bar: false)
            app_delegate.menu.toggle_left
          end

          def swap_center_controller(screen_class)
            # Just use screen_class if you don't need a navigation bar
            app_delegate.menu.center_controller = screen_class.new(nav_bar: true)
            app_delegate.menu.toggle_left
          end

        end
jamonholmgren commented 9 years ago

Hi @poc7667 , thanks for using ProMotion-menu!

A few things:

  1. Don't use application:didFinishLaunchingWithOptions: directly in a PM::Delegate. Instead, use on_load(app, options).
  2. In your fb screen, try this:
    class FbScreen < PM::Screen
        def load_webscreen
            app_delegate.menu.center = WebScreen.new(url: SITE_URL)
        end
    end