Пример #1
0
        private void MoveToForegroundLifecycleState()
        {
            lock (_lifecycleStateLock)
            {
                if (_currentReactContext != null)
                {
                    // We currently don't have an OnCreate callback so we call OnResume for both transitions
                    if (_lifecycleState == LifecycleState.Suspended ||
                        _lifecycleState == LifecycleState.BeforeCreate)
                    {
                        _currentReactContext.OnResume();
                        _currentReactContext.OnLeavingBackground();
                    }
                    else if (_lifecycleState == LifecycleState.Background)
                    {
                        _currentReactContext.OnLeavingBackground();
                    }
                }

                _lifecycleState = LifecycleState.Foreground;
            }
        }
Пример #2
0
        public void SetContext(ReactContext _reactContext)
        {
            lock (_lifecycleStateLock)
            {
                if (_currentReactContext != _reactContext)
                {
                    if (_currentReactContext != null)
                    {
                        // Suspend old context if needed. We don't touch the current lifecycle state.
                        if (_lifecycleState == LifecycleState.Foreground ||
                            _lifecycleState == LifecycleState.Background)
                        {
                            if (_lifecycleState == LifecycleState.Foreground)
                            {
                                _currentReactContext.OnEnteredBackground();
                            }
                            _currentReactContext.OnSuspend();
                        }
                    }

                    _currentReactContext = _reactContext;

                    if (_currentReactContext != null)
                    {
                        // Bring new context in sync with current lifecycle state
                        if (_lifecycleState == LifecycleState.Foreground ||
                            _lifecycleState == LifecycleState.Background)
                        {
                            _currentReactContext.OnResume();

                            if (_lifecycleState == LifecycleState.Foreground)
                            {
                                _currentReactContext.OnLeavingBackground();
                            }
                        }
                    }
                }
            }
        }