diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..423e72f --- /dev/null +++ b/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# gem "rails" +gem "just-the-docs" \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..fd78c59 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,74 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + colorator (1.1.0) + concurrent-ruby (1.1.8) + em-websocket (0.5.2) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0.6.0) + eventmachine (1.2.7) + ffi (1.15.0) + forwardable-extended (2.6.0) + http_parser.rb (0.6.0) + i18n (1.8.9) + concurrent-ruby (~> 1.0) + jekyll (4.2.0) + addressable (~> 2.4) + colorator (~> 1.0) + em-websocket (~> 0.5) + i18n (~> 1.0) + jekyll-sass-converter (~> 2.0) + jekyll-watch (~> 2.0) + kramdown (~> 2.3) + kramdown-parser-gfm (~> 1.0) + liquid (~> 4.0) + mercenary (~> 0.4.0) + pathutil (~> 0.9) + rouge (~> 3.0) + safe_yaml (~> 1.0) + terminal-table (~> 2.0) + jekyll-sass-converter (2.1.0) + sassc (> 2.0.1, < 3.0) + jekyll-seo-tag (2.7.1) + jekyll (>= 3.8, < 5.0) + jekyll-watch (2.2.1) + listen (~> 3.0) + just-the-docs (0.3.3) + jekyll (>= 3.8.5) + jekyll-seo-tag (~> 2.0) + rake (>= 12.3.1, < 13.1.0) + kramdown (2.3.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + liquid (4.0.3) + listen (3.4.1) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + mercenary (0.4.0) + pathutil (0.16.2) + forwardable-extended (~> 2.6) + public_suffix (4.0.6) + rake (12.3.2) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + rexml (3.1.9) + rouge (3.26.0) + safe_yaml (1.0.5) + sassc (2.4.0) + ffi (~> 1.9) + terminal-table (2.0.0) + unicode-display_width (~> 1.1, >= 1.1.1) + unicode-display_width (1.7.0) + +PLATFORMS + ruby + +DEPENDENCIES + just-the-docs + +BUNDLED WITH + 1.17.2 diff --git a/UITableView -> List/SwiftUI-List.md b/UITableView -> List/SwiftUI-List.md new file mode 100644 index 0000000..8f06bec --- /dev/null +++ b/UITableView -> List/SwiftUI-List.md @@ -0,0 +1,77 @@ +```Swift + +struct SongRow: View { + var song: Song + @Binding var isPlaying: Bool + + var body: some View { + HStack { + VStack(alignment: .leading) { + Text(song.name).bold() + Text(song.artist.name) + } + Spacer() + Button( + action: { self.isPlaying.toggle() }, + label: { + if isPlaying { + PauseIcon() + } else { + PlayIcon() + } + } + ) + } + } +} +``` + +Co the tach phan cac label cua button ra nhu duoi + +```Swift +private extension SongRow { + func makeButtonLabel() -> some View { + if isPlaying { + return AnyView(PauseIcon()) + } else { + return AnyView(PlayIcon()) + } + } +} +``` + +Chỗ này phải return AnyView vì thằng PauseIcon và PlayIcon khác type nhau + +Có một cách khác để xử lý vấn đề trên như sau: + +```Swift +private extension SongRow { + @ViewBuilder func makeButtonLabel() -> some View { + if isPlaying { + PauseIcon() + } else { + PlayIcon() + } + } +} +``` + +Với ViewBuilder thì ta không cần phải dùng AnyView nữa + +Lúc này có thể call như thằng + +```Swift +struct SongRow: View { + ... + + var body: some View { + HStack { + ... + Button( + action: { self.isPlaying.toggle() }, + label: { makeButtonLabel() } + ) + } + } +} +``` diff --git a/_config.yml b/_config.yml index c419263..d106c5b 100644 --- a/_config.yml +++ b/_config.yml @@ -1 +1 @@ -theme: jekyll-theme-cayman \ No newline at end of file +theme: just-the-docs \ No newline at end of file diff --git a/uikit_to_swiftui.md b/uikit_to_swiftui.md new file mode 100644 index 0000000..3e6f297 --- /dev/null +++ b/uikit_to_swiftui.md @@ -0,0 +1,23 @@ +| UIKit | Swift UI | +| ------------- | ------------- | +| UITableView | List | +| UILabel | Text | +| UITextField | TextField | +| UITextField secure | SecureField | +| UISwitch | Toggle | +| UISlider | Slider | +| UIButton | Button | +| UINavigationController | NavigationView | +| UIAlertController alert | Alert | +| UIAlertController action sheet | Action Sheet | +| UIStackView horizontal | HStack | +| UIStackView vertical | VStack | +| UIImageView | Image | +| UISegmentedControl | SegmentedControl | +| UIStepper | Stepper | +| UIDatePicker | DatePicker | +| UICollectionView | Not yet | +| UITextView | Not yet | +| | | +| UITableView section | Section | +| UIViewController | Combine | \ No newline at end of file