Skip to content

Commit

Permalink
Merge pull request #138 from muak/development
Browse files Browse the repository at this point in the history
implement cell reload
  • Loading branch information
muak authored Nov 11, 2020
2 parents 16f844d + 40aba9e commit 527203d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ public class Option
* IsEnabled
* セルを有効にするかどうか。無効にした場合はセル全体の色が薄くなり操作を受け付けなくなります。

### メソッド

* Reload
* セルを強制的にリロードします。CustomCell等で動的に内容を変更した後などに使用します。

### SVGイメージを使用するには

SvgImageSourceのnugetパッケージをインストールすればSVG画像を使用できるようになります。
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ public class Option
* IsEnabled
* Whether a cell is enabled. If set to false, the entire cell color will turn translucent and the cell won't accept any operations.

### Methods

* Reload
* Reload forcely the cell. This is used after dynamically changing the contents of a cell, such as Custom Cell.

### To use SVG image

You can use SVG image if SvgImageSource is installed.
Expand Down
19 changes: 19 additions & 0 deletions Sample/Sample/ViewModels/SurveyPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System.Collections.ObjectModel;
using Prism.Mvvm;
using Prism.Navigation;
using Reactive.Bindings;

namespace Sample.ViewModels
{
public class SurveyPageViewModel:BindableBase, INavigatedAware
{
public ObservableCollection<Hoge> ItemsSource { get; set; }
public ReactivePropertySlim<string> Text { get; } = new ReactivePropertySlim<string>();
public ReactiveCommand ChangeCommand { get; } = new ReactiveCommand();

public SurveyPageViewModel()
{
Expand All @@ -17,6 +20,22 @@ public SurveyPageViewModel()
new Hoge{Name="B",Value=2},
new Hoge{Name="C",Value=3}
});

Text.Value = "テキスト";

var toggle = true;
ChangeCommand.Subscribe(_ => {
if (toggle)
{
Text.Value = "テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト";
}
else
{
Text.Value = "テキスト";
}
toggle = !toggle;
});

}

public void OnNavigatedFrom(NavigationParameters parameters)
Expand Down
16 changes: 13 additions & 3 deletions Sample/Sample/Views/SurveyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
xmlns:sv="clr-namespace:AiForms.Renderers;assembly=SettingsView"
x:Class="Sample.Views.SurveyPage">

<Grid>
<sv:SettingsView x:Name="settings" HasUnevenRows="True" HeaderPadding="10" HeaderFontSize="16" HeaderTextVerticalAlign="Center" VerticalOptions="Start" BackgroundColor="AliceBlue" >
<sv:Section>
<sv:CustomCell x:Name="customCell">
<Label Text="{Binding Text.Value}" />
</sv:CustomCell>
</sv:Section>
</sv:SettingsView>

<sv:SettingsView x:Name="settings" HeaderPadding="10" HeaderFontSize="16" HeaderTextVerticalAlign="Center" VerticalOptions="Start" BackgroundColor="AliceBlue" >

</sv:SettingsView>
<Button VerticalOptions="End" Text="Layout" Margin="0,0,0,60" Clicked="Button_Clicked" />
<Button VerticalOptions="End" Text="Change" Command="{Binding ChangeCommand}" />
</Grid>


</ContentPage>
8 changes: 8 additions & 0 deletions Sample/Sample/Views/SurveyPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ protected override void OnAppearing()
settings.ScrollToBottom = true;
settings.ScrollToTop = true;
}

void Button_Clicked(System.Object sender, System.EventArgs e)
{
customCell.Reload();
//var section = settings.Root[0];
//var temp = section[0];
//section[0] = temp;
}
}
}
6 changes: 6 additions & 0 deletions SettingsView.Droid/FormsViewContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ protected virtual void CreateNewRenderer(Xamarin.Forms.View cell)

public void UpdateCell(Xamarin.Forms.View cell)
{
if(_formsCell == cell && !CustomCell.IsForceLayout)
{
return;
}
CustomCell.IsForceLayout = false;

if(_formsCell != null)
{
_formsCell.PropertyChanged -= CellPropertyChanged;
Expand Down
4 changes: 3 additions & 1 deletion SettingsView.iOS/Cells/CustomCellContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ protected virtual void UpdateIsEnabled()

public virtual void UpdateCell(View cell,UITableView tableView)
{
if(_formsCell == cell)
if (_formsCell == cell && !CustomCell.IsForceLayout)
{
return;
}
CustomCell.IsForceLayout = false;

if (_formsCell != null)
{
_formsCell.PropertyChanged -= CellPropertyChanged;
Expand Down
17 changes: 17 additions & 0 deletions SettingsView/Cells/CellBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ public class CellBase:Cell
Tapped(this, EventArgs.Empty);
}

public virtual void Reload()
{
if(Section == null)
{
return;
}
var index = Section.IndexOf(this);
if(index < 0)
{
return;
}

// raise replase event manually.
var temp = Section[index];
Section[index] = temp;
}

/// <summary>
/// The title property.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions SettingsView/Cells/CustomCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,12 @@ public void SendLongCommand()
LongCommand.Execute(BindingContext);
}
}

internal bool IsForceLayout = false;
public override void Reload()
{
IsForceLayout = true;
base.Reload();
}
}
}
1 change: 1 addition & 0 deletions nuget/AzurePipelines.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che

## New Features

* [Cell] Reload method.
* [SettingsView] ItemDroppedEvent and ItemDroppedCommand property.
* [TextPickerCell] IsCircularPicker property. #72
* [EntryCell] PlaceholderColor property #94
Expand Down

0 comments on commit 527203d

Please sign in to comment.