Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Term Entry] SwiftUI Concept: Buttons #5809

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

botaturganova
Copy link

Description

  • Added concept Buttons for SwiftUI

Issue Solved

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.

@CLAassistant
Copy link

CLAassistant commented Dec 11, 2024

CLA assistant check
All committers have signed the CLA.

@PragatiVerma18 PragatiVerma18 self-assigned this Dec 13, 2024
@PragatiVerma18 PragatiVerma18 added the status: under review Issue or PR is currently being reviewed label Dec 16, 2024
Copy link
Collaborator

@PragatiVerma18 PragatiVerma18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @botaturganova, thanks for contributing this entry. I have some suggestions, I have put some comments, please check them and do the required changes. Let me know if you have any questions.

content/swiftui/concepts/buttons/buttons.md Outdated Show resolved Hide resolved
Comment on lines +138 to +140
In this example:

The button displays an image and text.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an image example here.

content/swiftui/concepts/buttons/buttons.md Outdated Show resolved Hide resolved
content/swiftui/concepts/buttons/buttons.md Outdated Show resolved Hide resolved
Comment on lines +111 to +119
## Basic Button

A simple button in SwiftUI is created using the `Button` view. You can pass a closure (action) to the button that will be executed when the button is tapped:

```swift
Button("Tap Me") {
print("Button tapped!")
}
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Basic Button" section largely overlaps with the "Creating Buttons" section. Consolidating these or adding new value to the second section will improve the flow.

content/swiftui/concepts/buttons/buttons.md Outdated Show resolved Hide resolved
// Action here
}
.disabled(true)
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ButtonRole Information (iOS 15+). The new ButtonRole API in iOS 15+ allows buttons to have semantic roles like "destructive" or "cancel". Mentioning this improves completeness of this doc.

Starting in iOS 15, you can specify a `ButtonRole` (e.g., `.destructive` or `.cancel`) to provide semantic meaning to the button:
```swift
Button("Delete", role: .destructive) {
    print("Delete action")
}

## Creating Buttons

Buttons are created by specifying an action (code to execute when the button is tapped) and a label (the content of the button that is displayed to users). For example:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buttons in SwiftUI can use multiple types of views as labels, not just Text. This could be explicitly mentioned for beginners beforehand, but it should probably be covered in a Syntax header, and then usage should be explained in examples.

Buttons in SwiftUI can use any SwiftUI view as a label, not just `Text`. This allows for highly customizable and complex button content, such as combining icons, shapes, or even animations.

.background(Color.blue)
.cornerRadius(10)
}
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should include images and output on clicking the button in each case for good understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants