Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Formsで使えるライブラリやテクニックをご紹介 〜日本酒アプリSakenomyは、Forms...

Formsで使えるライブラリやテクニックをご紹介 〜日本酒アプリSakenomyは、Forms製です〜

JXUG#13発表資料
#ayasesh

yo ohtagawa

May 07, 2016
Tweet

More Decks by yo ohtagawa

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ ଠా઒ɹ༸ʢ͓͓͕ͨΘɹΑ͏ʣ • 2013೥4݄ גࣜձࣾΤϜςΟʔΞΠʹ৽ଔೖࣾ • ϞόΠϧΞϓϦέʔγϣϯΤϯδχΞ • ۀ຿ͰObjective-C &

    javaΛɺڵຯͰswift & kotlin • ̎೥લ͔Β Xamarin (iOS → Forms) • ઈࢍ TypeScript ͰͷϑϩϯτΤϯδχΞษڧத • twitter.com/AyaseSH • www.facebook.com/you.ootagawa
  2. Button inside Cell • એݴ࣌ʹॻ͖׵͑ΔͱViewCellʹҾ਺͕Θͨͤ·͢ɻ • CellͷதʹButtonͷ࣮૷͍ͨ࣌͠ɺActionΛ౉͢͜ͱͰ ListView͔ΒΠϕϯτͷίϯτϩʔϧ͕ग़དྷ·͢ɻ WBSMJTU7JFXOFX-JTU7JFX\ *UFN5FNQMBUFOFX%BUB5FNQMBUF

    UZQFPG 4BNQMF-JTU7JFX$FMM  *UFNT4PVSDFMJTU4PVSDF ^ WBSMJTU7JFXOFX-JTU7JFX\ *UFN5FNQMBUFOFX%BUB5FNQMBUF OFX4BNQMF-JTU7JFX$FMM  *UFNT4PVSDFMJTU4PVSDF ^
  3. Button inside Cell ※΍Γํ࣍ୈͰ͸ViewΛ౉͠ޙ෇΋Ͱ͖·͕͢ɺ X.Forms v2.1͔ΒTemplateΛෳ਺࣋ͯͨΓ͢ΔͷͰࠓ͸ඞཁͳ͍͔ͱࢥ͍·͢ "DUJPOUBQ 4ZTUFN%JBHOPTUJDT%FCVH8SJUF-JOF $BMMFE.FUIPE"DUJPO5BQ 

    WBSMJTU7JFXOFX-JTU7JFX\ *UFN5FNQMBUFOFX%BUB5FNQMBUF OFX4BNQMF-JTU7JFX$FMM UBQ  *UFNT4PVSDFMJTU4PVSDF  ^ QVCMJDDMBTT4BNQMF-JTU7JFX$FMM7JFX$FMM \ 4UBDL-BZPVU@TUBDL-BZPVU QVCMJD4BNQMF-JTU7JFX$FMM "DUJPOUBQ UIJT  \ WBSCVUUPOOFX#VUUPO \5FYU"EE#VUUPO 5FYU$PMPS$PMPS/BWZ^ CVUUPO$MJDLFE  TFOEFS F UBQ  @TUBDL-BZPVU$IJMESFO"EE OFX$POUFOU7JFX\ $POUFOUCVUUPO  7FSUJDBM0QUJPOT-BZPVU0QUJPOT$FOUFS ^  ^ ddd
  4. Button inside Cell • CellͷBindingContextʹදࣔͷσʔλ͕͋Δ • CellͰ্ॻ͖͢Ε͹σʔλ΋มΘΔ nextButton.Clicked += (sender,

    e) =>
 {
 var property = BindingContext as Property;
 BindingContext = new Helper().NextColor(property);
 };
 
 var beforeButton = new Button {
 Text = "Before",
 WidthRequest = 100,
 VerticalOptions = LayoutOptions.FillAndExpand
 };
 beforeButton.Clicked += (sender, e) =>
 {
 var property = BindingContext as Property;
 BindingContext = new Helper().BeforeColor(property);
 }; var listView = new ListView
 {
 ItemTemplate = new DataTemplate(() => new SampleListViewCell()),
 ItemsSource = new List<Property>(),
 HasUnevenRows = true,
 };
  5. Custom Url Scheme • Url Scheme ͱ͸ɺޚଘ஌ͷ௨Γ”http”ͷ͜ͱ • ϞόΠϧΞϓϦͰ͸
 SchemeΛมߋͨ͠ϦϯΫΛ౿·ͤΔͱରԠͨ͠ΞϓϦ

    ʹભҠͤ͞Δ͜ͱ͕Ͱ͖Δ࢓૊Έ • LINEͩͬͨΒ line:// ͳͲɹTwitterͰ͸ twitter:// ͳͲ • iOSͷUniversal Links͸৮Ε·ͤΜʢWebଆͷ࢓૊Έ͕ Α͘Θ͔ͬͯͳ͍…ʣ
  6. Android • MainActivity ʹ Attribute ௥Ճ // sakenomy-schemes://ayase.com/Sheeeeeeeep?id=1 [IntentFilter( new[]{

    Intent.ActionView }, 
 Categories = new[]{ Intent.CategoryDefault, Intent.CategoryBrowsable },
 DataScheme = "sakenomy-schemes",
 DataHost = "ayase.com",
 DataPathPrefix = “/Sheeeeeeeep", 
 DataPathPattern = “*")] public class MainActivity : FormsApplicationActivity {
 protected override void OnCreate(Android.OS.Bundle savedInstanceState) {
 ~~~ ~~~
 if (Intent.Data != null && !string.IsNullOrEmpty(Intent.Data.EncodedPath) && !string.IsNullOrEmpty(Intent.Data.EncodedQuery)) {
 var prefix = Intent.Data.EncodedPath;
 var id = Intent.Data.GetQueryParameter("id");
 
 if (Intent.Data.EncodedPath.Equals(“/Sheeeeeeeep”) {
 MessagingCenter.Send<App, string> (Xamarin.Forms.Application.Current as NSake.Core.App, "Ayase", id);
 } } }
  7. iOS 1. Info.plist > Advanced > URL Types > Add

    URL Type 2. AppDelegate.cs > OpenUrl Λ override // sakenomy-schemes://ayase.com/Sheeeeeeeep?id=1 public override bool OpenUrl (UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { if (url.LastPathComponent.Equals(“Sheeeeeeeep”) && url.Query.Contains(“id=")) { MessagingCenter.Send<App, string>(Xamarin.Forms.Application.Current as App, "Ayase", url.Query.Split(‘=')[1]); return true; } return false; }
  8. Xamarin.Forms • id͸AppͷҾ਺Ͱ౉͢͜ͱ΋Ͱ͖Δ͔ͳʁ • MessagingCenterΛ࢖༻ͨ͠ཧ༝͸ɺ
 ෳ਺ͷ࣮૷Λͨ࣌͠ʹɺCoreଆͷ࣮૷͕͖ͬ͢Γ • ͔͠͠ ֤ϓϥοτϑΥʔϜͰͷ࣮૷͸ ifจ

    ͷཛྷ… public App() { ~~~ ~~~ MessagingCenter.Subscribe <App, string>(this, "ShowTasted", (sender, arg) => naviPage.PushAsync(new AyasePage(arg))); // arg == id ~~~ ~~~
 }
  9. FFImageLoading ػೳҰཡ • ϝϞϦΩϟογϡͱͦͷσΟεΫ༰ྔͷઃ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