Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Meshtastic-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
0D4E46F725D3C3C5008686AB /* LogManagerTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4E46F625D3C3C5008686AB /* LogManagerTemplate.swift */; };
0DEE520925D0BA71003C6EB7 /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = 0DEE520825D0BA71003C6EB7 /* SwiftProtobuf */; };
0DEE520D25D0BE8B003C6EB7 /* DeviceDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DEE520C25D0BE8B003C6EB7 /* DeviceDetailView.swift */; };
8A713CD02623EAD300F6D4BB /* MessageKit in Frameworks */ = {isa = PBXBuildFile; productRef = 8A713CCF2623EAD300F6D4BB /* MessageKit */; };
D5248FC6251ED2FA00CF50E6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D5248FC5251ED2FA00CF50E6 /* Assets.xcassets */; };
D5248FC9251ED2FA00CF50E6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D5248FC7251ED2FA00CF50E6 /* LaunchScreen.storyboard */; };
D55AC0AB25D0A52700151E9D /* DeviceInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55AC0AA25D0A52700151E9D /* DeviceInfo.swift */; };
Expand Down Expand Up @@ -69,6 +70,7 @@
buildActionMask = 2147483647;
files = (
0DEE520925D0BA71003C6EB7 /* SwiftProtobuf in Frameworks */,
8A713CD02623EAD300F6D4BB /* MessageKit in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -190,6 +192,7 @@
name = Meshtastic;
packageProductDependencies = (
0DEE520825D0BA71003C6EB7 /* SwiftProtobuf */,
8A713CCF2623EAD300F6D4BB /* MessageKit */,
);
productName = "M-iOS_test";
productReference = D5248FB9251ED2F900CF50E6 /* Meshtastic.app */;
Expand Down Expand Up @@ -220,6 +223,7 @@
mainGroup = D5248FB0251ED2F900CF50E6;
packageReferences = (
0DEE520725D0BA71003C6EB7 /* XCRemoteSwiftPackageReference "swift-protobuf" */,
8A713CCE2623EAD300F6D4BB /* XCRemoteSwiftPackageReference "MessageKit" */,
);
productRefGroup = D5248FBA251ED2F900CF50E6 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -407,7 +411,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = SKJCUF8GFH;
DEVELOPMENT_TEAM = NLSA9C94UQ;
INFOPLIST_FILE = Meshtastic/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -426,7 +430,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = SKJCUF8GFH;
DEVELOPMENT_TEAM = NLSA9C94UQ;
INFOPLIST_FILE = Meshtastic/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -471,6 +475,14 @@
minimumVersion = 1.15.0;
};
};
8A713CCE2623EAD300F6D4BB /* XCRemoteSwiftPackageReference "MessageKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/MessageKit/MessageKit";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.3.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -479,6 +491,11 @@
package = 0DEE520725D0BA71003C6EB7 /* XCRemoteSwiftPackageReference "swift-protobuf" */;
productName = SwiftProtobuf;
};
8A713CCF2623EAD300F6D4BB /* MessageKit */ = {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If MessageKit is not used can you please remove it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What's the proper way to do this?

isa = XCSwiftPackageProductDependency;
package = 8A713CCE2623EAD300F6D4BB /* XCRemoteSwiftPackageReference "MessageKit" */;
productName = MessageKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = D5248FB1251ED2F900CF50E6 /* Project object */;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 181 additions & 8 deletions Meshtastic/Views/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,194 @@

import SwiftUI



struct ChatView: View {
// @State private var messageInput = ""
// @State private var chatHistory = ""

var body: some View {
NavigationView {
Form {
Section {
Text("Chat message")
}
}
.navigationBarTitle(Text("Chat"))
}
// VStack {
// ScrollView {
// LazyVStack(alignment: .leading, spacing: 32) {
// ForEach(0 ..< 12) { _ in
// TextField("Lorem Ipsum Lorem Ipsum", text: $chatHistory)
// }
//
// }
// }
// TextField("Message", text: $messageInput)
// .frame(width: 300, height: 40)
// .font(Font.system(size: 15, weight: .semibold))
// .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.blue, lineWidth: 1))
// .padding()
// }


// Borrowed from KavSoft
chatInstance()







}
}


struct ChatView_Previews: PreviewProvider {
static var previews: some View {
ChatView()
}
}


struct chatInstance : View {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[nitpick] let's follow Swift standards and name structs with the capital letter


@State var txt = ""
@State var height : CGFloat = 0
@State var keyboardHeight : CGFloat = 0

var body: some View {
VStack (spacing: 0) {

HStack {
Text("Chat")
.font(.title)
.fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/)

Spacer()
}.padding()
.background(Color.white)

Spacer()

ScrollView(.vertical, showsIndicators: false) {

// Chat Content
Text("")
}

HStack(spacing: 8) {

resizeableChat(txt: self.$txt, height: self.$height)
.frame(height: self.height < 150 ? self.height : 150)
.padding(.horizontal)
.background(Color.white)
.cornerRadius(15)
Button(action: {

}) {

Image(systemName: "arrow.forward.circle")
.font(.system(size: 18, weight: .regular))
.foregroundColor(.black)
.padding(10)
}
.background(Color.white)
.clipShape(Circle())
}
.padding(.horizontal)

}
.padding(.bottom, self.keyboardHeight)
.background(Color.black.opacity(0.06).edgesIgnoringSafeArea(.bottom)
.onTapGesture {

UIApplication.shared.windows.first?.rootViewController?.view
.endEditing(true)
})
.onAppear {

NotificationCenter.default.addObserver(forName:
UIResponder.keyboardDidShowNotification, object: nil, queue: .main) {
(data) in

let height1 = data.userInfo![UIResponder.keyboardFrameEndUserInfoKey]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[critical] forced unwrapping is not good, can cause a crash

as! NSValue

self.keyboardHeight = height1.cgRectValue.height - 20

}

NotificationCenter.default.addObserver(forName:
UIResponder.keyboardDidHideNotification, object: nil, queue: .main) {
(_) in

self.keyboardHeight = 0

}
}
}
}


struct resizeableChat : UIViewRepresentable {

@Binding var txt: String
@Binding var height : CGFloat

func makeCoordinator() -> Coordinator {

return resizeableChat.Coordinator(parent1: self)
}


func makeUIView(context: Context) -> UITextView {

let view = UITextView()
view.isEditable = true
view.isScrollEnabled = true
view.text = "Enter Message"
view.font = .systemFont(ofSize: 18)
view.textColor = .gray
view.backgroundColor = .clear
view.delegate = context.coordinator
return view
}

func updateUIView(_ uiView: UITextView, context: Context) {
DispatchQueue.main.async {

self.height = uiView.contentSize.height
}
}

class Coordinator : NSObject, UITextViewDelegate {

var parent : resizeableChat

init(parent1 : resizeableChat) {

parent = parent1
}

func textViewDidBeginEditing(_ textView: UITextView) {

if self.parent.txt == "" {

textView.text = ""
textView.textColor = .black
}
}

func textViewDidEndEditing(_ textView: UITextView) {
if self.parent.txt == ""{

textView.text = "Enter Message"
textView.textColor = .gray
}
}

func textViewDidChange(_ textView: UITextView) {

DispatchQueue.main.async {
self.parent.height = textView.contentSize.height
self.parent.txt = textView.text

}
}
}
}