Skip to content

Commit

Permalink
Merge pull request #62 from muak/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
muak authored Jun 1, 2019
2 parents ebcf47d + b475f33 commit 7de8be2
Show file tree
Hide file tree
Showing 20 changed files with 633 additions and 149 deletions.
100 changes: 99 additions & 1 deletion README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Android:version 5.1.1 (only FormsAppcompatActivity) / API22
Install-Package AiForms.SettingsView
```

PCLプロジェクトと各プラットフォームにインストールが必要です
NETStandardプロジェクトと各プラットフォームにインストールが必要です

### iOSの場合

Expand All @@ -67,6 +67,20 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
}
```

### Androidの場合

Androidで使用する場合はMainActivity.csに以下のようなコードを書く必要があります。

```csharp
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
AiForms.Renderers.Droid.SettingsViewInit.Init(); // need to write here
}
```

## Xamlでの使用方法

```xml
Expand Down Expand Up @@ -218,6 +232,61 @@ SettingsView の内容のセルの合計の高さが、親のViewよりも低い
</sv:SettingsView>
```

### SetttingsView自身のItemsSourceとItemTemplateの使用例

```csharp
public class SomeViewModel
{
public List<MenuSection> ItemsSource {get;set;}

public SomeViewModel()
{
ItemsSource = new List<MenuSection>{
new new MenuSection("Select number",3){
new MenuItem{Title = "3",Value=3},
new MenuItem{Title = "4",Value=4},
},
new MenuSection("Select mode",1){
new MenuItem{Title = "A",Value = 1},
new MenuItem{Title = "B",Value = 2}
}
}
}
}
public class MenuItem
{
public string Title { get; set; }
public int Value { get; set; }
}

public class MenuSection:List<MenuItem>
{
public string SectionTitle { get; set; }
public bool Selected { get;set; } // must implement INotifyPropertyChanged by some way
public MenuSection(string title,int initalSelectedValue)
{
SectionTitle = title;
}
}
```

```xml
<sv:SettingsView x:Name="Settings" ItemsSource="{Binding ItemsSource}">
<sv:SettingsView.ItemTemplate>
<DataTemplate>
<sv:Section Title="{Binding SectionTitle}" ItemsSource="{Binding}" sv:RadioCell.SelectedValue="{Binding Selected}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:RadioCell Title="{Binding Title}" Value="{Binding Value}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
</DataTemplate>
</sv:SettingsView.ItemTemplate>
</sv:SettingsView>
```

## SettingsViewのメソッド

* ClearCache (static)
Expand All @@ -243,6 +312,35 @@ SettingsView の内容のセルの合計の高さが、親のViewよりも低い
* iOS11以降とそれ以外で外観が異なります。
* iOS10以下は三本線のアイコンを掴むと移動でき、iOS11はセル全体を長押しすると移動できるようになります。

### セクションのItemsSourceとItemTemplateの使用例

```csharp
public class SomeModel
{
// 動的なリストを使う場合はObservableCollectionを使った方が良いです。
public ObservableCollection<Option> Options {get;set;}
public void SomeMethod()
{
Options = new ObservableCollection(GetServerData());
}
}
public class Option
{
public string Name {get;set;}
public string Address {get;set;}
}
```

```xml
<sv:Section ItemsSource="{Binding Options}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:LabelCell Title="{Binding Name}" Value="{Binding Address}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
```

## Cells

* [CellBase](#cellbase)
Expand Down
102 changes: 100 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ Install-Package AiForms.SettingsView

You need to install this nuget package to .NETStandard project and each platform project.

### for iOS project
### For iOS

To use by iOS, you need to write some code in AppDelegate.cs.
AppDelegate.cs

```csharp
public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
Expand All @@ -68,6 +68,20 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
}
```

### For Android

MainActivity.cs

```csharp
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

global::Xamarin.Forms.Forms.Init(this, bundle);
AiForms.Renderers.Droid.SettingsViewInit.Init(); // need to write here
}
```

## How to write with xaml

```xml
Expand Down Expand Up @@ -217,6 +231,61 @@ If SettingsView's total cells height is shorter than the parent view height, its
</sv:SettingsView>
```

### Sample of ItemsSource and ItemTemplate for a root

```csharp
public class SomeViewModel
{
public List<MenuSection> ItemsSource {get;set;}

public SomeViewModel()
{
ItemsSource = new List<MenuSection>{
new new MenuSection("Select number",3){
new MenuItem{Title = "3",Value=3},
new MenuItem{Title = "4",Value=4},
},
new MenuSection("Select mode",1){
new MenuItem{Title = "A",Value = 1},
new MenuItem{Title = "B",Value = 2}
}
}
}
}
public class MenuItem
{
public string Title { get; set; }
public int Value { get; set; }
}

public class MenuSection:List<MenuItem>
{
public string SectionTitle { get; set; }
public bool Selected { get;set; } // must implement INotifyPropertyChanged by some way
public MenuSection(string title,int initalSelectedValue)
{
SectionTitle = title;
}
}
```

```xml
<sv:SettingsView x:Name="Settings" ItemsSource="{Binding ItemsSource}">
<sv:SettingsView.ItemTemplate>
<DataTemplate>
<sv:Section Title="{Binding SectionTitle}" ItemsSource="{Binding}" sv:RadioCell.SelectedValue="{Binding Selected}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:RadioCell Title="{Binding Title}" Value="{Binding Value}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
</DataTemplate>
</sv:SettingsView.ItemTemplate>
</sv:SettingsView>
```

## SettingsView Methods

* ClearCache (static)
Expand All @@ -241,6 +310,35 @@ If SettingsView's total cells height is shorter than the parent view height, its
* Enable you to reorder cells in a section with drag and drop.
* If iOS version is less than or equal to iOS10, the cells can be moved when grabbing the icon drawn three lines; Otherwise can be moved when doing long tap.

### How to use an ItemsSource and an ItemTemplate for a Section

```csharp
public class SomeModel
{
// you should use a ObservableCollection if you use a dynamic list.
public ObservableCollection<Option> Options {get;set;}
public void SomeMethod()
{
Options = new ObservableCollection(GetServerData());
}
}
public class Option
{
public string Name {get;set;}
public string Address {get;set;}
}
```

```xml
<sv:Section ItemsSource="{Binding Options}">
<sv:Section.ItemTemplate>
<DataTemplate>
<sv:LabelCell Title="{Binding Name}" Value="{Binding Address}" />
</DataTemplate>
</sv:Section.ItemTemplate>
</sv:Section>
```

## Cells

* [CellBase](#cellbase)
Expand Down
3 changes: 1 addition & 2 deletions Sample/Sample.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ protected override void OnCreate(Bundle bundle)
global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");
global::Xamarin.Forms.Forms.Init(this, bundle);
Xamarin.Forms.Svg.Droid.SvgImage.Init();

var a = new AiForms.Renderers.Droid.PickerCellRenderer();
AiForms.Renderers.Droid.SettingsViewInit.Init();

LoadApplication(new App(new AndroidInitializer()));
}
Expand Down
Loading

0 comments on commit 7de8be2

Please sign in to comment.