public void EncodeState(NSObject item, NSCoder state, IDataContext context = null) { Should.NotBeNull(item, nameof(item)); Should.NotBeNull(state, nameof(state)); var controller = item as UIViewController; if (controller != null && string.IsNullOrEmpty(controller.RestorationIdentifier)) { return; } var view = item as UIView; if (view != null && string.IsNullOrEmpty(view.RestorationIdentifier)) { return; } var navigationParameter = (item as UIViewController).GetNavigationParameter(); if (navigationParameter != null) { state.Encode(new NSString(navigationParameter), ParameterStateKey); } var viewModel = item.DataContext() as IViewModel; if (viewModel != null) { state.Encode(new NSString(viewModel.GetType().AssemblyQualifiedName), VmTypeKey); PreserveViewModel(viewModel, item, state, context ?? DataContext.Empty); } }
public void DecodeState(NSObject item, NSCoder state, IDataContext context = null) { Should.NotBeNull(item, nameof(item)); Should.NotBeNull(state, nameof(state)); RestoreNavigationParameter(item, state); if (!state.ContainsKey(VmTypeKey)) { return; } var vmTypeName = (NSString)state.DecodeObject(VmTypeKey); if (vmTypeName == null) { return; } object dataContext = item.DataContext(); var vmType = Type.GetType(vmTypeName, false); if (vmType != null && (dataContext == null || !dataContext.GetType().Equals(vmType))) { if (context == null) { context = DataContext.Empty; } RestoreViewModel(vmType, RestoreViewModelState(item, state, context), item, state, context); } }
/// <summary> /// Occurs on load element state. /// </summary> public void DecodeState(NSObject item, NSCoder state, IDataContext context = null) { Should.NotBeNull(item, "item"); Should.NotBeNull(state, "state"); RestoreNavigationParameter(item, state); if (!state.ContainsKey(VmTypeKey)) return; var vmTypeName = (NSString)state.DecodeObject(VmTypeKey); if (vmTypeName == null) return; object dataContext = item.DataContext(); var vmType = Type.GetType(vmTypeName, false); if (vmType != null && (dataContext == null || !dataContext.GetType().Equals(vmType))) { if (context == null) context = DataContext.Empty; RestoreViewModel(vmType, RestoreViewModelState(item, state, context), item, state, context); } }
/// <summary> /// Occurs on save element state. /// </summary> public void EncodeState(NSObject item, NSCoder state, IDataContext context = null) { Should.NotBeNull(item, "item"); Should.NotBeNull(state, "state"); var controller = item as UIViewController; if (controller != null && string.IsNullOrEmpty(controller.RestorationIdentifier)) return; var view = item as UIView; if (view != null && string.IsNullOrEmpty(view.RestorationIdentifier)) return; object navigationParameter = (item as UIViewController).GetNavigationParameter(); if (navigationParameter != null) { using (Stream stream = _serializer.Serialize(navigationParameter)) state.Encode(stream.ToArray(), ParameterStateKey); } var viewModel = item.DataContext() as IViewModel; if (viewModel != null) { state.Encode(new NSString(viewModel.GetType().AssemblyQualifiedName), VmTypeKey); PreserveViewModel(viewModel, item, state, context ?? DataContext.Empty); } }