• Stars
    star
    252
  • Rank 161,312 (Top 4 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SwiftUI Chat UI (Client) Framework & Documentation to get started!

Version Swift 5.3

SwiftyChat

For Flutter version check this link

Content

About

Simple Chat Interface to quick start with built-in message cells.
Fully written in pure SwiftUI.

Features

  • HTML String support like <li>, <a> (not like h1 or font based tag)
  • Attributed string support that contains address, date, phoneNumber, url (text is automatically scanned)
  • Landscape orientation support (autoscales message cells with the given cellWidth property, if exists)
  • User Avatar (with different position options, optional usage)
  • Dismiss keyboard (on tapping outside).
  • Multiline Input Bar added (investigate BasicInputView)
  • Scroll to bottom.
  • Round specific corner of text messages.
  • Implement custom message cells. See CustomMessage.md for details.
  • Swipe to dismiss keyboard.

Quick Preview

Basic Example Preview
Text (Light) Text (Dark)
Advanced Example Preview
Contact, QuickReply, Text, Carousel Map, Image ContextMenu

Installation

SPM: https://github.com/EnesKaraosman/SwiftyChat.git

Message Kinds

public enum ChatMessageKind {
    
    /// A text message,
    /// supports emoji 👍🏻 (auto scales if text is all about emojis)
    case text(String)
    
    /// An image message, from local(UIImage) or remote(URL).
    case image(ImageLoadingKind)
    
    /// A location message, pins given location & presents on MapKit.
    case location(LocationItem)
    
    /// A contact message, generally for sharing purpose.
    case contact(ContactItem)
    
    /// Multiple options, disables itself after selection.
    case quickReply([QuickReplyItem])
    
    /// `CarouselItem`s that contains title, subtitle, image & button in a scrollable view
    case carousel([CarouselItem])
    
    /// A video message, opens the given URL.
    case video(VideoItem)
}

Usage

  • ChatView

Here below is minimum code required to get started (see up & running)
For detail, visit example project here

@State private var scrollToBottom = false
@State private var messages: [MockMessages.ChatMessageItem] = [] // for quick test assign MockMessages.generatedMessages()

// ChatMessageItem & ChatUserItem is a sample objects/structs 
// that conforms `ChatMessage` & `ChatUser` protocols.
ChatView<MockMessages.ChatMessageItem, MockMessages.ChatUserItem>(
    messages: $messages,
    scrollToBottom: $scrollToBottom
) {
    // InputView here, continue reading..
}
// ▼ Required
.environmentObject(
    // All parameters initialized by default, 
    // change as you want.
    ChatMessageCellStyle()
)
.onReceive(
    messages.debounce(for: .milliseconds(650), scheduler: RunLoop.main),
    perform: { _ in
        scrollToBottom = true
    }
)
...
...
  • InputView

You can investigate existing BasicInputView in project.
You can use it if it suits your need, or create a new one.
Recommended way is just clone this BasicInputView and modify (ex. add camera icon etc.)

// InputBarView variables
@State private var message = ""
@State private var isEditing = false

var inputBarView: some View {
    BasicInputView(
        message: $message, // Typed text.
        isEditing: $isEditing,
        placeholder: "Type something",
        onCommit: { messageKind in
            self.messages.append(
                .init(user: MockMessages.sender, messageKind: messageKind, isSender: true)
            )
        }
    )
    .padding(8)
    .padding(.bottom, isEditing ? 0 : 8)
    .accentColor(.chatBlue)
    .background(Color.primary.colorInvert())
    // ▼ An extension that wraps view inside AnyView
    .embedInAnyView()
}

// Pass in ChatView
ChatView(messages: $messages) {
    inputBarView 
}
...
...

Style and Customization

public class ChatMessageCellStyle: ObservableObject {
    
    let incomingTextStyle: TextCellStyle
    let outgoingTextStyle: TextCellStyle
    
    let incomingCellEdgeInsets: EdgeInsets
    let outgoingCellEdgeInsets: EdgeInsets
    
    let contactCellStyle: ContactCellStyle
    
    let imageCellStyle: ImageCellStyle
    
    let quickReplyCellStyle: QuickReplyCellStyle
    
    let carouselCellStyle: CarouselCellStyle
    
    let locationCellStyle: LocationCellStyle
    
    let incomingAvatarStyle: AvatarStyle
    let outgoingAvatarStyle: AvatarStyle
    
}

You must initiate this class to build a proper style & inject it as environmentObject,
All styles has default initializer;

For detail documentation, visit Styles.md

You can also use your own custom message cell, see CustomMessage.md for details.


Please feel free to contribute.
* Create PR for a feature/bug you'd like to add/fix.

Dependencies

Inspiration

More Repositories

1

SwipeCell

Swipe Left2Right & Right2Left, pure SwiftUI implementation
Swift
271
star
2

JSONDrivenUI

JSON into native SwiftUI View to build UI for iOS.
Swift
81
star
3

DesignDetective

Compare your implementation and design, see how much they match!
Swift
44
star
4

SwiftUIEKtensions

Extensions for SwiftUI
Swift
22
star
5

swifty_chat

A Chat package for flutter
Dart
21
star
6

SwiftProgress

Progress Bars for SwiftUI
Swift
19
star
7

StarView

SwiftUI StarView Shape, usable for displaying ratings
Swift
16
star
8

LoremSwiftify

LoremSwiftify is a Macro that creates lorem ipsum data for your models
Swift
14
star
9

SwiftEmptyState

Displaying Empty state of a page. (UIKit)
Swift
11
star
10

SocialLogins

Makes social logins easier for iOS
Swift
7
star
11

Swinjector

Simple dependency injection package inspired by get_it Flutter package
Swift
5
star
12

dart_kotlin_swift_comparison

This repo contains some kind of cheatsheet to quickly compare the basics of `Dart` `Kotlin` and `Swift`.
5
star
13

swifty_chat_data

Data package for the swifty_chat package.
Dart
4
star
14

iOSBaseProject

You're gonna start to a new project and fed up doing same initialization every time.
Swift
4
star
15

SettingsBundleDemo

Swift
3
star
16

CollapsibleCollectionView

Collapse CollectionView
Swift
2
star
17

efficient_indexed_stack

C++
2
star
18

bottom_sheet_routing

This repository demonstrates the usage of bottom sheet and inner routing. Represents the usage with core Navigator & auto_route
C++
1
star
19

EKNetworkModule

A generic, helper, util implementation of Network (Alamofire+SwiftyJSON)
Swift
1
star
20

iOS-Development-Resources

1
star
21

UI

Swift
1
star