public void ReplaceProperties(ResizeGroupState <TObject> nextState) { if (nextState.RenderedData != null) { this.RenderedData = nextState.RenderedData; } if (nextState.DataToMeasure != null) { this.DataToMeasure = nextState.DataToMeasure; } if (nextState.ResizeDirection != ResizeDirection.None) { this.ResizeDirection = nextState.ResizeDirection; } this.MeasureContainer = nextState.MeasureContainer; if (nextState.NullifyDataToMeasure) { this.DataToMeasure = default; } if (nextState.NullifyRenderedData) { this.RenderedData = default; } if (nextState.ForceNoneResizeDirection) { this.ResizeDirection = ResizeDirection.None; } }
private ResizeGroupState <TObject> UpdateContainerDimension(double newDimension, TObject fullDimensionData, TObject renderedData) { ResizeGroupState <TObject> nextState; if (double.IsNaN(_containerDimension)) { throw new Exception("The containerDimension was not supposed to be NaN"); } if (newDimension > _containerDimension) { if (OnGrowData != null) { nextState = new ResizeGroupState <TObject>(ResizeDirection.Grow, OnGrowData(renderedData)); } else { nextState = new ResizeGroupState <TObject>(ResizeDirection.Shrink, fullDimensionData); } } else { nextState = new ResizeGroupState <TObject>(ResizeDirection.Shrink, renderedData); } _containerDimension = newDimension; nextState.MeasureContainer = false; return(nextState); }
private async Task <ResizeGroupState <TObject> > GetNextStateAsync(double newContainerDimension, double oldContainerDimension, TObject dataToMeasure, TObject renderedData, ResizeDirection resizeDirection, CancellationToken cancellationToken) { double replacementContainerDimension = oldContainerDimension; if (double.IsNaN(newContainerDimension) && dataToMeasure == null) { return(null); } if (!double.IsNaN(newContainerDimension)) { // If we know what the last container size was and we rendered data at that width/height, we can do an optimized render if (!double.IsNaN(oldContainerDimension) && renderedData != null && dataToMeasure == null) { var state = new ResizeGroupState <TObject>(renderedData, resizeDirection, dataToMeasure); var alteredState = UpdateContainerDimension(oldContainerDimension, newContainerDimension, this.Data, renderedData); state.ReplaceProperties(alteredState); return(state); } replacementContainerDimension = newContainerDimension; } var nextState = new ResizeGroupState <TObject>(renderedData, resizeDirection, dataToMeasure); nextState.MeasureContainer = false; if (replacementContainerDimension != oldContainerDimension) { nextState.ContainerDimension = replacementContainerDimension; } if (dataToMeasure != null) { //get elementDimension here var elementDimension = await GetElementDimensionsAsync(cancellationToken); if (resizeDirection == ResizeDirection.Grow && this.OnGrowData != null) { var alteredState = GrowDataUntilItDoesNotFit(dataToMeasure, elementDimension, replacementContainerDimension); nextState.ReplaceProperties(alteredState); } else { var alteredState = ShrinkContentsUntilTheyFit(dataToMeasure, elementDimension, replacementContainerDimension); nextState.ReplaceProperties(alteredState); } } return(nextState); }
private async Task <ResizeGroupState <TObject> > GetNextStateAsync(double containerDimension) { if (double.IsNaN(containerDimension) && _dataToMeasure == null) { return(null); } if (!double.IsNaN(containerDimension)) { // If we know what the last container size was and we rendered data at that width/height, we can do an optimized render if (!double.IsNaN(_containerDimension) && _renderedData != null && _dataToMeasure == null) { var state = new ResizeGroupState <TObject>(_renderedData, _resizeDirection, _dataToMeasure); var alteredState = UpdateContainerDimension(containerDimension, this.Data, _renderedData); state.ReplaceProperties(alteredState); return(state); } _containerDimension = containerDimension; } var nextState = new ResizeGroupState <TObject>(_renderedData, _resizeDirection, _dataToMeasure); nextState.MeasureContainer = false; if (_dataToMeasure != null) { //get elementDimension here var elementDimension = await GetElementDimensionsAsync(); if (_resizeDirection == ResizeDirection.Grow && this.OnGrowData != null) { var alteredState = GrowDataUntilItDoesNotFit(_dataToMeasure, elementDimension); nextState.ReplaceProperties(alteredState); } else { var alteredState = ShrinkContentsUntilTheyFit(_dataToMeasure, elementDimension); nextState.ReplaceProperties(alteredState); } } return(nextState); }