Skip to content

Commit 527203d

Browse files
authored
Merge pull request #138 from muak/development
implement cell reload
2 parents 16f844d + 40aba9e commit 527203d

File tree

10 files changed

+84
-4
lines changed

10 files changed

+84
-4
lines changed

README-ja.md

+5
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ public class Option
452452
* IsEnabled
453453
* セルを有効にするかどうか。無効にした場合はセル全体の色が薄くなり操作を受け付けなくなります。
454454

455+
### メソッド
456+
457+
* Reload
458+
* セルを強制的にリロードします。CustomCell等で動的に内容を変更した後などに使用します。
459+
455460
### SVGイメージを使用するには
456461

457462
SvgImageSourceのnugetパッケージをインストールすればSVG画像を使用できるようになります。

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ public class Option
449449
* IsEnabled
450450
* Whether a cell is enabled. If set to false, the entire cell color will turn translucent and the cell won't accept any operations.
451451

452+
### Methods
453+
454+
* Reload
455+
* Reload forcely the cell. This is used after dynamically changing the contents of a cell, such as Custom Cell.
456+
452457
### To use SVG image
453458

454459
You can use SVG image if SvgImageSource is installed.

Sample/Sample/ViewModels/SurveyPageViewModel.cs

+19
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
using System.Collections.ObjectModel;
44
using Prism.Mvvm;
55
using Prism.Navigation;
6+
using Reactive.Bindings;
67

78
namespace Sample.ViewModels
89
{
910
public class SurveyPageViewModel:BindableBase, INavigatedAware
1011
{
1112
public ObservableCollection<Hoge> ItemsSource { get; set; }
13+
public ReactivePropertySlim<string> Text { get; } = new ReactivePropertySlim<string>();
14+
public ReactiveCommand ChangeCommand { get; } = new ReactiveCommand();
1215

1316
public SurveyPageViewModel()
1417
{
@@ -17,6 +20,22 @@ public SurveyPageViewModel()
1720
new Hoge{Name="B",Value=2},
1821
new Hoge{Name="C",Value=3}
1922
});
23+
24+
Text.Value = "テキスト";
25+
26+
var toggle = true;
27+
ChangeCommand.Subscribe(_ => {
28+
if (toggle)
29+
{
30+
Text.Value = "テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト";
31+
}
32+
else
33+
{
34+
Text.Value = "テキスト";
35+
}
36+
toggle = !toggle;
37+
});
38+
2039
}
2140

2241
public void OnNavigatedFrom(NavigationParameters parameters)

Sample/Sample/Views/SurveyPage.xaml

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
xmlns:sv="clr-namespace:AiForms.Renderers;assembly=SettingsView"
66
x:Class="Sample.Views.SurveyPage">
77

8+
<Grid>
9+
<sv:SettingsView x:Name="settings" HasUnevenRows="True" HeaderPadding="10" HeaderFontSize="16" HeaderTextVerticalAlign="Center" VerticalOptions="Start" BackgroundColor="AliceBlue" >
10+
<sv:Section>
11+
<sv:CustomCell x:Name="customCell">
12+
<Label Text="{Binding Text.Value}" />
13+
</sv:CustomCell>
14+
</sv:Section>
15+
</sv:SettingsView>
816

9-
<sv:SettingsView x:Name="settings" HeaderPadding="10" HeaderFontSize="16" HeaderTextVerticalAlign="Center" VerticalOptions="Start" BackgroundColor="AliceBlue" >
10-
11-
</sv:SettingsView>
17+
<Button VerticalOptions="End" Text="Layout" Margin="0,0,0,60" Clicked="Button_Clicked" />
18+
<Button VerticalOptions="End" Text="Change" Command="{Binding ChangeCommand}" />
19+
</Grid>
20+
21+
1222
</ContentPage>

Sample/Sample/Views/SurveyPage.xaml.cs

+8
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@ protected override void OnAppearing()
1818
settings.ScrollToBottom = true;
1919
settings.ScrollToTop = true;
2020
}
21+
22+
void Button_Clicked(System.Object sender, System.EventArgs e)
23+
{
24+
customCell.Reload();
25+
//var section = settings.Root[0];
26+
//var temp = section[0];
27+
//section[0] = temp;
28+
}
2129
}
2230
}

SettingsView.Droid/FormsViewContainer.cs

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ protected virtual void CreateNewRenderer(Xamarin.Forms.View cell)
132132

133133
public void UpdateCell(Xamarin.Forms.View cell)
134134
{
135+
if(_formsCell == cell && !CustomCell.IsForceLayout)
136+
{
137+
return;
138+
}
139+
CustomCell.IsForceLayout = false;
140+
135141
if(_formsCell != null)
136142
{
137143
_formsCell.PropertyChanged -= CellPropertyChanged;

SettingsView.iOS/Cells/CustomCellContent.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ protected virtual void UpdateIsEnabled()
7777

7878
public virtual void UpdateCell(View cell,UITableView tableView)
7979
{
80-
if(_formsCell == cell)
80+
if (_formsCell == cell && !CustomCell.IsForceLayout)
8181
{
8282
return;
8383
}
84+
CustomCell.IsForceLayout = false;
85+
8486
if (_formsCell != null)
8587
{
8688
_formsCell.PropertyChanged -= CellPropertyChanged;

SettingsView/Cells/CellBase.cs

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ public class CellBase:Cell
1919
Tapped(this, EventArgs.Empty);
2020
}
2121

22+
public virtual void Reload()
23+
{
24+
if(Section == null)
25+
{
26+
return;
27+
}
28+
var index = Section.IndexOf(this);
29+
if(index < 0)
30+
{
31+
return;
32+
}
33+
34+
// raise replase event manually.
35+
var temp = Section[index];
36+
Section[index] = temp;
37+
}
38+
2239
/// <summary>
2340
/// The title property.
2441
/// </summary>

SettingsView/Cells/CustomCell.cs

+7
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,12 @@ public void SendLongCommand()
167167
LongCommand.Execute(BindingContext);
168168
}
169169
}
170+
171+
internal bool IsForceLayout = false;
172+
public override void Reload()
173+
{
174+
IsForceLayout = true;
175+
base.Reload();
176+
}
170177
}
171178
}

nuget/AzurePipelines.nuspec

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che
2121

2222
## New Features
2323

24+
* [Cell] Reload method.
2425
* [SettingsView] ItemDroppedEvent and ItemDroppedCommand property.
2526
* [TextPickerCell] IsCircularPicker property. #72
2627
* [EntryCell] PlaceholderColor property #94

0 commit comments

Comments
 (0)