Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Vincent Hoogendoorn
    @VincentH-Net
    So you'r on to ssomething
    Mihhail Maslakov
    @ionoy
    so content shows now?
    what is the other issue?
    Vincent Hoogendoorn
    @VincentH-Net
    Yes :-) Also tested other issue that is fixeed as wwell
    other issue was keyboard accessory not showiing
    Mihhail Maslakov
    @ionoy
    ok, this sounds good!
    now I need to understand what was special about your view models
    Vincent Hoogendoorn
    @VincentH-Net
    OK, but output windoow does flood with:
    09-06 11:44:08.223 I/mono-stdout(14355): received 0 bytes
    received 0 bytes
    received 0 bytes
    received 0 bytes
    received 0 bytes
    received 0 bytes
    received 0 bytes
    received 0 bytes
    Mihhail Maslakov
    @ionoy
    because all I did was I commented out IReflectableType injection
    Vincent Hoogendoorn
    @VincentH-Net
    Ok. do you want views or viewmodels?
    Mihhail Maslakov
    @ionoy
    viewmodels
    network stuff doesn't seem to be a bug for me, I'll check it out though
    Vincent Hoogendoorn
    @VincentH-Net
        public partial class BaseModel : BaseViewModel
        {
            static JsonSerializerSettings apiJsonSettings;
    
            [AttributeUsage(validOn: AttributeTargets.Property, Inherited = false)]
            protected class JsonIgnoreForApiAttribute : Attribute { }
    
            public string SerializeToJsonForApi()
            {
                if (apiJsonSettings == null)
                    apiJsonSettings = new JsonSerializerSettings { ContractResolver = new IgnoreContractResolver(typeof(JsonIgnoreForApiAttribute)) };
    
                return Json.SerializeObject(this, apiJsonSettings);
            }
    
            public PreserializedJsonObject PreSerializeToJsonForApi() => new PreserializedJsonObject { Json = SerializeToJsonForApi() };
        }
    
        public abstract class BaseViewModel : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;
    
            protected virtual void RaisePropertyChanged(string propertyName)
            {
                var handler = PropertyChanged;
                if (handler != null) TaskHelper.RunOnUIThread(() => handler(this, new PropertyChangedEventArgs(propertyName)));
            }
    
            /// <summary>
            /// Check this property when you receive events from outside the viewmodel, e.g. from services.
            /// If IsShowing is true then it is a good time to update data-bound properties;
            /// if IsShowing is false then you could set a dirty flag, so later in OnShow() you can retrieve 
            /// changed data and update any changed data-bound properties.
            /// </summary>
            [JsonIgnore]
            public bool IsShowing { get; private set; }
    
            /// <summary>
            /// This method is called when a view becomes visible. 
            /// You can override this method to update
            /// data-bound properties for any changes that originated from outside the viewmodel, 
            /// e.g. changes in service model objects that you were notified about in service events that you
            /// subscribed to in the viewmodel.
            /// 
            /// Always call base.OnShow() at the start of your method when you override it!
            /// 
            /// The view base classes call this method on the following view lifecycle events: 
            /// iOS:     TODO
            /// Android: TODO
            /// Windows: OnNavigatedTo
            /// </summary>
            public virtual void OnShow()
            {
                IsShowing = true;
            }
    
            /// <summary>
            /// This method is called when a view becomes invisible. 
            /// You can override this method to handle any tasks that do not belong in OnUserInteractionStopped().
            /// 
            /// Always call base.OnHide() at the end of your method when you override it!
            /// 
            /// The view base classes call this method on the following view lifecycle events: 
            /// iOS:     TODO
            /// Android: TODO
            /// Windows: OnNavigatingFrom
            /// </summary>
            public virtual void OnHide() { IsShowing = false; OnUserInteractionStopped(); }
    
            /// <summary>
            /// This method is called when the user is done interacting with the viewmodel.
            /// <example>E.g. override this method to save changes in the viewmodel without the need for a save button.</example>
            /// <remarks>The standard QuickCross implementation will call this method from lifecycle events,
            /// such as when the app is stopped or when navigating away from a view.
            /// You could also call this method on other moments, e.g. when the user is inactive for a number of seconds.</remarks>
            /// </summary>
            public virtual void OnUserInteractionStopped() { }
        }
    Note that I am also using Fody PropertyChanged
    Mihhail Maslakov
    @ionoy
    maybe it has something to do with fody?
    Vincent Hoogendoorn
    @VincentH-Net
    Not sure what you do with viewmodels? I thought you only inject code in Page build methods?
    Mihhail Maslakov
    @ionoy
    viewmodels are injected with IReflectableType to allow Binding to read dynamically added properties
    Vincent Hoogendoorn
    @VincentH-Net
    Aha
    But that is the issue then
    Mihhail Maslakov
    @ionoy
    because internally Xamarin.Forms uses IReflectableType interface to create bindings
    at least it can use that
    Vincent Hoogendoorn
    @VincentH-Net
    Let me disassemble what fody adds
    one oment
    Mihhail Maslakov
    @ionoy
    yeah, this cuts an important feature for now, that's why I'm trying to understand what's going on
    Vincent Hoogendoorn
    @VincentH-Net
    public abstract class BaseViewModel : INotifyPropertyChanged
    {
        [JsonIgnore]
        public bool IsShowing
        {
            [CompilerGenerated]
            get
            {
                return IsShowing;
            }
            [CompilerGenerated]
            private set
            {
                if (IsShowing != value)
                {
                    IsShowing = value;
                    RaisePropertyChanged("IsShowing");
                }
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected unsafe virtual void RaisePropertyChanged(string propertyName)
        {
            //IL_0035: Unknown result type (might be due to invalid IL or missing references)
            //IL_003f: Expected O, but got Unknown
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                <>c__DisplayClass3_0 <>c__DisplayClass3_;
                TaskHelper.RunOnUIThread(new Action((object)<>c__DisplayClass3_, (IntPtr)(void*)/*OpCode not supported: LdFtn*/));
            }
        }
    
        public virtual void OnShow()
        {
            IsShowing = true;
        }
    
        public virtual void OnHide()
        {
            IsShowing = false;
            OnUserInteractionStopped();
        }
    
        public virtual void OnUserInteractionStopped()
        {
        }
    }
    Mihhail Maslakov
    @ionoy
    nothing stands out to me tbh
    I'll try to create a test project
    btw, I've found the network issue. it should be fixed in the next NuGet release
    Vincent Hoogendoorn
    @VincentH-Net

    Great! On a viewmodel fody does this:

    Source:

            public string UserPhoneNumber { get; set; }
    
            public bool IsCallAvailable => IsDemo || !string.IsNullOrWhiteSpace(UserPhoneNumber);

    Decompiled:

        public string UserPhoneNumber
        {
            [CompilerGenerated]
            get
            {
                return UserPhoneNumber;
            }
            [CompilerGenerated]
            set
            {
                if (!string.Equals(UserPhoneNumber, value, StringComparison.Ordinal))
                {
                    UserPhoneNumber = value;
                    RaisePropertyChanged("IsCallAvailable");
                    RaisePropertyChanged("CanRegister");
                    RaisePropertyChanged("IsRegisterEnabled");
                    RaisePropertyChanged("RegisterPhoneNumberCommand");
                    RaisePropertyChanged("IsNewUserPhoneNumberRegistered");
                    RaisePropertyChanged("CanTest");
                    RaisePropertyChanged("UserPhoneNumber");
                }
            }
        }
    
        public bool IsCallAvailable => IsDemo || !string.IsNullOrWhiteSpace(UserPhoneNumber);
    Mihhail Maslakov
    @ionoy
    yeah, that seems normal to me
    Vincent Hoogendoorn
    @VincentH-Net
    Do you have enough info to fix the issue?
    Mihhail Maslakov
    @ionoy
    not sure yet, but I got an NRE when using your baseviewmodel with fody
    the thing is, you didn't have any exceptions
    so it might be different
    Vincent Hoogendoorn
    @VincentH-Net
    Or your VS tooling just less brooken :-)
    Nothing surprises me with Xamarin tools
    Mihhail Maslakov
    @ionoy
    that also maybe true :)
    Vincent Hoogendoorn
    @VincentH-Net
    Oh but you dont have TaskHelper.RunOnUIThread
    Mihhail Maslakov
    @ionoy
    i replaced it with Device.BeginInvokeOnMainThread
    plus it's not called in my case at all
    Vincent Hoogendoorn
    @VincentH-Net
    Ok I'm going for a short walk. Back in 20 min
    Mihhail Maslakov
    @ionoy
    ok, thank you very much for helping!
    Mihhail Maslakov
    @ionoy
    I have found an issue. Not sure if this is the same issue you were having :)
    Vincent Hoogendoorn
    @VincentH-Net
    Ok. Maybe something channged in Forms? I did update
    Mihhail Maslakov
    @ionoy
    this fix needs dynamic system rewrite, so it might take a few days. but I was planning on doing it anyway, just a bit later
    so hopefully this also fixes your problem
    Vincent Hoogendoorn
    @VincentH-Net
    Fingers crossed. I can work around the issue for now, feel free to let me test before you publish
    Mihhail Maslakov
    @ionoy
    sure
    Vincent Hoogendoorn
    @VincentH-Net
    ONly I dont get Gitter notifications so better ping me on twitter
    Gitter notifications are broken a long time. They wont fix. Stubborn
    Mihhail Maslakov
    @ionoy
    yeah, seems so