Contact views

FUIContactCell

FUIContactCell is a subclass of UITableViewCell, with a UIImageView, vertically-stacked labels, and an FUIActivityControl component, containing activity items for launching various communication channels. The implementation of the communication channel can be set by the developer.

Image

Usage

In UITableViewDataSource tableView(_:cellForRowAt:) method, dequeue a FUIContactCell, and bind to data.

Though both options are marked public, you should always use the <property>Text: String and <property>Image: UIImage properties to set cell content, instead of directly setting values to the @IBOutlet. This allows the implementation to optimize the constraints for the given content. It is fine to set other properties of the @IBOutlet, such as font style or color, opacity, etc.

let cell = tableView.dequeueReusableCell(withIdentifier: FUIContactCell.reuseIdentifier) as! FUIContactCell

// You can customize your own activity object
let myCustomActivity = FUIActivityItem(icon: UIImage(named: "asset"), identifier: "mycustom.activity")
let activities: [FUIActivityItem] = [FUIActivityItem.phone, FUIActivityItem.message, myCustomActivity]

// You are responsible to have a data source which contains basic information of the contacts
let contact = self.contacts[indexPath.row]

contactCell.detailImage = contact.image
contactCell.headlineText = contact.name
contactCell.subheadlineText = contact.title
contactCell.descriptionText = contact.address
contactCell.activityControl.addActivities(activities)

// Optionally, set the fraction of "main" content width, of total cell width (defaults to `0.5`)
contactCell.mainStackWidth = 0.5

// MARK - OPTION A (closure API)
contactCell.onActivitySelectedHandler = { activityItem in
    <#handler#>
}

// MARK - OPTION B (delegate API)
contactCell.delegate = self

FUIContactCell supports two API styles for handling FUIActivityItem selection: closure, and delegate. Only one should be implemented on a cell instance at a time. Behavior is undefined, if both are implemented.

Option A: Implement onActivitySelectedHandler closure to handle FUIActivityItem selection events:

cell.onActivitySelectedHandler = { activityItem in

    switch activityItem {
    case FUIActivityItem.phone:
        contact.call()
    case FUIActivityItem.message:
        contact.sendMessage()
    case FUIActivityItem.videoCall:
        contact.video()
    default:
        break
    }
}

Option B: Implement FUIContactCell delegate method to handle FUIContactCell actions:

func contactCell(_ contactCell: FUIContactCell, didSelectActivity activityItem: FUIActivityItem) {
    let indexPath: IndexPath = self.tableView.indexPath(for: contactCell)!
    let targetContact = self.contacts[indexPath.row]

    switch activityItem {
        case FUIActivityItem.phone:
            //Do something
        case FUIActivityItem.message:
            //Do something
        case myCustomActivity:
            //Do something
        default:
            break
    }
}

FUIActivityControl

FUIActivityControl is a stand alone component supporting user activities. By default, it supports phone, email, message, videoCall.

Code usage:

 //You can create your own activity object if you want.
 let myCustomActivity = FUIActivityItem(icon: UIImage(named: "asset"), identifier: "mycustomer.twilio")
 let activities: [FUIActivityItem] = [FUIActivityItem.phone, FUIActivityItem.message, myCustomActivity]

 //Create a FUIActivityControl object.
 let activityControl = FUIActivityControl()
 activityControl.addActivities(activities)
 activityControl.delegate = SomeClass()

 //Optionally, set an item size (if nil, intrinsic size of image will be used)
 activityControl.itemSize = CGSize(width: 44.0, height: 44.0)

 //Optionally, set a limit to visible items (useful for hiding items in `.compact` horizontal mode)
 activityControl.maxVisibleItems = 3

 //Optionally, set the inter-item spacing (useful for showing more items in `.compact` horizontal mode)
 activityControl.spacing = 29.0

 cell.contentView.addSubview(activityControl)
 activityControl.translatesAutoresizingMaskIntoConstraints = false
 activityControl.leadingAnchor.constraint(equalTo: (cell.contentView.layoutMarginsGuide.leadingAnchor)).isActive = true
 activityControl.topAnchor.constraint(equalTo: (cell.contentView.layoutMarginsGuide.topAnchor)).isActive = true
 activityControl.bottomAnchor.constraint(equalTo: (cell.contentView.layoutMarginsGuide.bottomAnchor)).isActive = true

 //Implement this method in your action handler class.
 func activityControl(_ activityControl: FUIActivityControl, didSelectActivity activityItem: FUIActivityItem) {
     switch activityItem {
         case FUIActivityItem.phone:
            //do something
         case FUIActivityItem.message:
            //do something
         case myCustomActivity:
            //do something
         default:
            break
     }
 }
  • FUIContactCell is variant of UITableViewCell defined in SAPFiori. It contains a UIImageView, several UILabels and a FUIActivityControl component.

    FUIContactCell

    Code usage:

     //Developer needs to define MyContactObject and DataSource first.

    //Contact object mockup class MyContactObject { var name: String var title: String var address: String var image: UIImage init(name: String, title: String, address: String, image: UIImage) { self.name = name self.title = title self.address = address self.image = image }   func call(){ // dial the phone number } func sendMessage(){ // locate assistant contact info & email } }

    
     //Create a FUIContactCell in a TableView
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCell(withIdentifier: FUIContactCell.reuseIdentifier) as! FUIContactCell
         let activities: [ActivityItem] = [ActivityItem.phone, ActivityItem.message]
         let contact = DataSource.contact[indexPath.row]
         cell.detailImage = contact.image
         cell.headlineText = contact.name
         cell.subheadlineText = contact.title
         cell.descriptionText = contact.address
         cell.activityControl.addActivities(activities)

    // Optionally, adjust activity item size (defaults to CGSize(width: 25.0, height: 25.0)) self.activityControl.itemSize = CGSize(width: 25, height: 25) // Optionally, adjust limit on visible items in activity control (defaults to 3) self.activityControl.maxVisibleItems = 3 // Optionally, adjust activity control spacing (defaults to 29.0) self.activityControl.stackView.spacing = 29.0

    // Implement onActivitySelectedHandler. cell.onActivitySelectedHandler = { activityItem in

        <span class="k">switch</span> <span class="n">activityItem</span> <span class="p">{</span>
        <span class="k">case</span> <span class="kt">ActivityItem</span><span class="o">.</span><span class="nv">phone</span><span class="p">:</span>
            <span class="k">let</span> <span class="nv">_</span> <span class="o">=</span> <span class="n">contact</span><span class="o">.</span><span class="nf">call</span><span class="p">()</span>
        <span class="k">case</span> <span class="kt">ActivityItem</span><span class="o">.</span><span class="nv">message</span><span class="p">:</span>
            <span class="k">let</span> <span class="nv">_</span> <span class="o">=</span> <span class="n">contact</span><span class="o">.</span><span class="nf">sendMessage</span><span class="p">()</span>
        <span class="k">case</span> <span class="kt">ActivityItem</span><span class="o">.</span><span class="nv">videoCall</span><span class="p">:</span>
            <span class="k">let</span> <span class="nv">_</span> <span class="o">=</span> <span class="n">contact</span><span class="o">.</span><span class="nf">video</span><span class="p">()</span>
        <span class="k">default</span><span class="p">:</span>
            <span class="k">break</span>
        <span class="p">}</span>
    <span class="p">}</span>
    

    }

    See more

    Declaration

    Swift

    open class FUIContactCell: NibDesignableTableViewCell, FUIActivityControlDelegate
  • This protocol provides method for handling activity action in a contact cell.

    See more

    Declaration

    Swift

    public protocol FUIContactCellDelegate: class
  • FUIActivityItem is a activity object that activity control supports. Activities supported by default including: phone, email, message, videoCall and detail

    See more

    Declaration

    Swift

    public struct FUIActivityItem: Equatable, Hashable
  • FUIActivityControl is a stand-alone component supporting user activities. By default, it supports phone, email, message, videoCall. FUIContactCell embed with a FUIActivityControl by default.

    Code usage:

     //You can create your own activity object if you want.
     let myCustomActivity = FUIActivityItem(icon: UIImage(named: asset), identifier: mycustomer.twilio)
     let activities: [FUIActivityItem] = [FUIActivityItem.phone, FUIActivityItem.message, myCustomActivity]

    //Create a FUIActivityControl object. let activityControl = FUIActivityControl() activityControl.addActivities(activities) activityControl.delegate = self

    //Optionally, set an item size (if nil, intrinsic size of image will be used) activityControl.itemSize = CGSize(width: 44.0, height: 44.0)

    //Optionally, set a limit to visible items (useful for hiding items in .compact horizontal mode) activityControl.maxVisibleItems = 3

    //Optionally, set the inter-item spacing (useful for showing more items in .compact horizontal mode) activityControl.spacing = 29.0

    //Implement this method in your class to handle action. func activityControl(_ activityControl: FUIActivityControl, didSelectActivity activityItem: FUIActivityItem) { switch activityItem { case FUIActivityItem.phone: //do something case FUIActivityItem.message: //do something case myCustomActivity: //do something default: break } }

    See more

    Declaration

    Swift

    open class FUIActivityControl: NibDesignable
  • This protocol provides method for handling activity action in a activity control component.

    See more

    Declaration

    Swift

    public protocol FUIActivityControlDelegate: class