Skip to content

Commit

Permalink
optional Challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-007 committed Jul 19, 2020
1 parent 5db4e5c commit fa943b6
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
4 changes: 4 additions & 0 deletions SwiftUIChallenge/SwiftUIChallenge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
EE7666C624B1C06900224A66 /* AddOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE7666C324B1C06900224A66 /* AddOverlay.swift */; };
EE7666C724B1C06900224A66 /* OutlinedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE7666C424B1C06900224A66 /* OutlinedText.swift */; };
EE76DB3D24C307F400BEC679 /* ContactDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE76DB3C24C307F400BEC679 /* ContactDetails.swift */; };
EE76DB3F24C419C200BEC679 /* ScrollViewWithSegmentControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE76DB3E24C419C200BEC679 /* ScrollViewWithSegmentControl.swift */; };
EE8D6D9024BC948C00F26B34 /* GradientButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8D6D8F24BC948C00F26B34 /* GradientButtonStyle.swift */; };
EE8D6D9224BC95D000F26B34 /* ButtonChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8D6D9124BC95D000F26B34 /* ButtonChallenge.swift */; };
EE8D6D9624BC97D400F26B34 /* ShadowButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8D6D9524BC97D400F26B34 /* ShadowButtonStyle.swift */; };
Expand All @@ -41,6 +42,7 @@
EE7666C324B1C06900224A66 /* AddOverlay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddOverlay.swift; sourceTree = "<group>"; };
EE7666C424B1C06900224A66 /* OutlinedText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OutlinedText.swift; sourceTree = "<group>"; };
EE76DB3C24C307F400BEC679 /* ContactDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactDetails.swift; sourceTree = "<group>"; };
EE76DB3E24C419C200BEC679 /* ScrollViewWithSegmentControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewWithSegmentControl.swift; sourceTree = "<group>"; };
EE8D6D8F24BC948C00F26B34 /* GradientButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientButtonStyle.swift; sourceTree = "<group>"; };
EE8D6D9124BC95D000F26B34 /* ButtonChallenge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonChallenge.swift; sourceTree = "<group>"; };
EE8D6D9524BC97D400F26B34 /* ShadowButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowButtonStyle.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -123,6 +125,7 @@
children = (
EE5CA8EB24C2D36D008830E6 /* ListWithSegmentedControlChallenge.swift */,
EE76DB3C24C307F400BEC679 /* ContactDetails.swift */,
EE76DB3E24C419C200BEC679 /* ScrollViewWithSegmentControl.swift */,
);
path = SegmentedControl;
sourceTree = "<group>";
Expand Down Expand Up @@ -236,6 +239,7 @@
EE48E38A24ADAED300EC6B66 /* ImageChallengeView.swift in Sources */,
EE76DB3D24C307F400BEC679 /* ContactDetails.swift in Sources */,
EE7666C524B1C06900224A66 /* UIView+Custom.swift in Sources */,
EE76DB3F24C419C200BEC679 /* ScrollViewWithSegmentControl.swift in Sources */,
EE7666C724B1C06900224A66 /* OutlinedText.swift in Sources */,
EE91A59D24BA489E00B225C2 /* StackChallengeView.swift in Sources */,
EE5CA8EC24C2D36D008830E6 /* ListWithSegmentedControlChallenge.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,99 @@
import SwiftUI

struct ScrollViewWithSegmentControl: View {
@State private var sortingIndex = 0
@State var contacts : [ContactInfo] = [.init(name: "John", email: "john@apple.com", number: "123567890"),
.init(name: "Albert", email: "albert@apple.com", number: "123567890"),
.init(name: "Bruce", email: "bruce@apple.com", number: "123567890"),
.init(name: "Sean", email: "sean@apple.com", number: "123567890"),
.init(name: "Robert", email: "robert@apple.com", number: "123567890"),
.init(name: "Albert", email: "albert@apple.com", number: "123567890"),
.init(name: "Francis", email: "francis@apple.com", number: "123567890"),
.init(name: "Joseph", email: "joseph@apple.com", number: "123567890"),
.init(name: "Adam", email: "adam@apple.com", number: "123567890"),
.init(name: "Lucifer", email: "lucifer@apple.com", number: "123567890")]

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
NavigationView {
VStack {
Picker("Sort Contacts by", selection: $sortingIndex) {
Text("Name").tag(0)
Text("Email").tag(1)
}.pickerStyle(SegmentedPickerStyle())
.onReceive([self.sortingIndex].publisher.first(), perform: { (tag) in
// Here you would want to write your custom logic to perform some operations on segment change
switch tag {
case 0:
contacts.sort { $0.email < $1.email }
case 1:
contacts.sort { $0.name > $1.name }
default:
break
}
})
.padding()
ScrollView {
ForEach(contacts, id:\.self) { contact in
NavigationLink(destination: ContactDetails(contactInfo: contact)) {
ListContactCell(contactInfo: contact)
}
}
}
Spacer()
}.navigationTitle("Contacts")
}
}

}

struct ScrollViewWithSegmentControl_Previews: PreviewProvider {
static var previews: some View {
ScrollViewWithSegmentControl()
}
}

struct ListContactCell: View {
@State private var showingAlert = false

var contactInfo: ContactInfo
var body: some View {
HStack {
VStack(alignment: .leading, spacing: 5) {
Text(contactInfo.name)
.fontWeight(.bold)
.font(.system(size: 18))
.foregroundColor(.black)
Text(contactInfo.email)
.fontWeight(.semibold)
.font(.system(size: 16))
.foregroundColor(.black)
}
Spacer()
Button(action: sendMessage) {
Image(systemName: "message.fill")
.frame(width: 40, height: 40, alignment: .center)
.font(.body)
.foregroundColor(.green)
}.alert(isPresented: $showingAlert) {
Alert(title: Text("Still in Development"), message: Text("Once implementation is complete you will be able to send a text message or make a video call"), dismissButton: .default(Text("Got it!")))
}
Button(action: makeVideoCall) {
Image(systemName: "video.fill")
.frame(width: 40, height: 40, alignment: .center)
.font(.body)
.foregroundColor(.red)
}.alert(isPresented: $showingAlert) {
Alert(title: Text("Still in Development"), message: Text("Once implementation is complete you will be able to send a text message or make a video call"), dismissButton: .default(Text("Got it!")))
}
}.padding(.leading, 20)
.padding(.trailing, 20)
}

func makeVideoCall() {
self.showingAlert = true
}

func sendMessage() {
self.showingAlert = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
struct SwiftUIChallengeApp: App {
var body: some Scene {
WindowGroup {
ListWithSegmentedControlChallenge()
ScrollViewWithSegmentControl()
}
}
}

0 comments on commit fa943b6

Please sign in to comment.