MoathOthman / MOLH

Localization helper for iOS apps mainly focusing on the LTR/RTL issue
MIT License
117 stars 36 forks source link

application restart not working as well #46

Closed Emy87aa closed 4 years ago

Emy87aa commented 4 years ago

WhatsApp Image 2019-12-04 at 2 17 24 PM

When restarting the app this happens, nil in rootViewController

MoathOthman commented 4 years ago

Hey eman , can you provide more details about the environment . What did you do ?

Sent from my iPhone

On Dec 4, 2019, at 3:06 PM, Eman Alsabbagh notifications@github.com wrote:

 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Emy87aa commented 4 years ago

I edited the issue and added screen Shot

supergenedy commented 4 years ago

@Emy87aa I made a solution for this issue till MoathOthman updates the lib you can add this func in your AppDelegate it gets the window from SceneDelegate

 @available(iOS 13.0, *)
    func swichRoot(){
        //Flip Animation before changing rootView
        animateView()

        // switch root view controllers
        let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
        let nav = storyboard.instantiateViewController(withIdentifier: "HomeView")

        let scene = UIApplication.shared.connectedScenes.first
        if let sd : SceneDelegate = (scene?.delegate as? SceneDelegate) {
            sd.window!.rootViewController = nav
        }

    }
   @available(iOS 13.0, *)
    func animateView() {
        var transition = UIView.AnimationOptions.transitionFlipFromRight
        if !MOLHLanguage.isRTLLanguage() {
            transition = .transitionFlipFromLeft
        }
       animateView(transition: transition)
    }

    @available(iOS 13.0, *)
    func animateView(transition: UIView.AnimationOptions) {
        if let delegate = UIApplication.shared.connectedScenes.first?.delegate {
            UIView.transition(with: (((delegate as? SceneDelegate)!.window)!), duration: 0.5, options: transition, animations: {}) { (f) in
            }
        }
    }

You can check if ios > 13 then call this func from the AppDelegate

        if #available(iOS 13.0, *) {
                let delegate = UIApplication.shared.delegate as? AppDelegate
                delegate!.swichRoot()
        } else {
               // Fallback on earlier versions
               MOLH.reset()
        }

And also check if ios > 13 in the reset func in the AppDelegate to call swichRoot func

MoathOthman commented 4 years ago

@supergenedy thanx for the solution .

imuhammadjabbar commented 4 years ago

@supergenedy thanx for the solution .

@MoathOthman it does solve the animation crash issue but the language is not getting translated.

supergenedy commented 4 years ago

@imuhammadjabbar did you call MOLH.setLanguageTo("YOUR_LANGUAGE") ?

imuhammadjabbar commented 4 years ago

@imuhammadjabbar did you call MOLH.setLanguageTo("YOUR_LANGUAGE") ?

Yes, I did. ( MOLH.setLanguageTo(currentLanguage == "en" ? "ar" : "en") ) I set my default Language to Ar.

Seems like it is changing now. But My Side Menu is not working. or some images. How can I change images manually(There were changing automatically with Changing System LAnguage)

And the side menu is not working as well.

Any help would be much appreciated. Thanks

MoathOthman commented 4 years ago

@imuhammadjabbar there is a function for images image.flipIfNeeded()

abdallahnh commented 4 years ago

The crash is happening because we are forced unwrapping the window

MoathOthman commented 4 years ago

fixed in 1.3