Swiftpack.co -  ExpediaInc/tokens-ios as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
ExpediaInc/tokens-ios
Created by https://ewe.builds.sb.karmalab.net/job/bex-app-ios-mirror-ios-tokens/
.package(url: "https://github.com/ExpediaInc/tokens-ios.git", from: "3.77.1")

EGDS Tokens iOS

A library of Swift packages supporting brand EGDS tokens. These packages provide Swift types for consuming various types of design tokens in both UIKit and SwiftUI.

This library is generated, do not attempt to modify directly.

Important

You should not directly consume tokens-ios as it is a dependency for other token libraries. Contant @bmunge or @kioreilly for assistance setting up a new repo

Currently set up repositories:

Installation

Swift Package Manager

Adding to an existing package

// swift-tools-version:5.3

import PackageDescription

let package = Package(
  name: "YourTestProject",
  platforms: [
       .iOS(.v13),
  ],
  dependencies: [
    .package(url: "https://github.expedia.biz/egds/tokens-ios.git", .exact("0.1.0"))
  ],
  targets: [
    .target(name: "YourTestProject", dependencies: ["EGDSTokensDefault"])
  ]
)

Adding to an existing iOS project via Swift Package Manager

  1. Using Xcode 12 go to File > Swift Packages > Add Package Dependency
  2. Paste the project SSH URL: git@github.expedia.biz:egds/tokens-ios.git
  3. Click on next and select the brand targets you which to import.

Note: You must include EGDSTokensDefault to receive the core objects and default EGDS token set.

package selection

Initialization

In your App Delegate, you should import and select the appropriate brand token set.

import UIKit
import EGDSTokensExpedia

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        EGDSExpediaTokenActivator.activate()
        return true
    }

Building & archiving without custom build configurations (app just uses Debug & Release)

This should work out of the box

Building & archiving with custom build configurations

SPM does not work so well with custom build configurations so there are a few steps to follow for successful builds. Trying to import library and building will result in a "Bundle not found" error

To avoid the Bundle error, an empty folder for each bundle needs to be created before buidl. For the required scheme, add a pre-action in Build

mkdir -p $SYMROOT/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensHotels_EGDSTokensHotels.bundle
mkdir -p $SYMROOT/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensDefault_EGDSTokensDefault.bundle

Next, a run script which will create a tmp directory to store the files in and then copy the swiftmodule in to the right place The first half of the script is handling getting the Bundles into an easily accessible location to then copy them back in to the app in the archive step following. The second half of the script is placing the module content in the correct location so the build is able to succeed.

mkdir ~/Desktop/tmp
defaultPath=$(readlink $SYMROOT/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/EGDSTokensHotels_EGDSTokensHotels.bundle)
hotelsPath=$(readlink $SYMROOT/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/EGDSTokensDefault_EGDSTokensDefault.bundle)
cp -f -R $defaultPath ~/Desktop/tmp
cp -f -R $hotelsPath ~/Desktop/tmp

mkdir -p "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensHotels.swiftmodule/"
mkdir -p "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensDefault.swiftmodule/"
rsync -r "${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/EGDSTokensHotels.swiftmodule/" "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensHotels.swiftmodule/"
rsync -r "${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/EGDSTokensDefault.swiftmodule/" "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/EGDSTokensDefault.swiftmodule/"

An Archive post-action is also required

rsync -r --copy-links ~/Desktop/tmp/* "${ARCHIVE_PRODUCTS_PATH}/Applications/MainUI-App-HotelsCom.app/"

Referencing Tokens

When referencing tokens, simply import EGDSTokensDefault to reference any tokens available in the default EGDS token set. To reference tokens added by a particular brand, you'll need to import that brand separately.

It's important to consider that token values will be set by whatever brand you initialized in your app delegate. Make sure that your brand contains values for all the tokens you are referencing.

Usage Guidelines

Supported Token Types

Color

UIKit

Color tokens are available as static variables in an extension on UIColor

import EGDSTokensDefault

func setColors() {
  label.textColor = UIColor.linkDefaultText
  view.backgroundColor = UIColor.canvasDefaultBackground
}

SwiftUI

Color tokens are available as static variables in an extension on Color

var body: some View {
  Text("VIP")
    .foregroundColor(.badgeVipText)
    .background(Color.badgeVipBackground)
}

Font

UIKit

Font tokens are available as static variables in an extension on UIFont

import EGDSTokensDefault

func setFonts() {
  badgeLabel.font = UIFont.badgeLarge
  headingLabel.font = UIFont.font700Bold
}

SwiftUI

Font tokens are available as static variables in an extension on Font

var body: some View {
  Text("VIP")
    .font(.badgeSmall)
}

Breakpoint

Breakpoint tokens are available as static CGFloat variables in an extension on Breakpoint.

import EGDSTokensDefault

func setBreakpoint() {
  maxScreenWidth = Breakpoint.largeMax
}

Corner Radius

Corner Radius tokens are available as static CGFloat variables in an extension on CornerRadius.

import EGDSTokensDefault

func setCornerRadii() {
  view.layer.cornerRadius = CornerRadius.cornerRadius2x
  badge.layer.cornerRadius = CornerRadius.badge
}

Sizing

Sizing tokens are available as static CGFloat variables in an extension on Sizing.

import EGDSTokensDefault

func setSizing() {
  vipBadge.layer.borderWidth = Sizing.badgeVipBorderWidth
  iconHeightConstraint.constant = Sizing.iconMSizing
}

Spacing

Spacing tokens are available as static CGFloat variables in an extension on Spacing.

import EGDSTokensDefault

func setSpacing() {
  horizontalSpacingConstraint.constant = Spacing.badgeSpacingInnerHoriz()
  stackView.layoutMargins = UIEdgeInsets(top: Spacing.spacing0x(), left: Spacing.spacing1x(), bottom: Spacing.spacing0x, right: Spacing.spacing1x())
  stackView.isLayoutMarginsRelativeArrangement = true
}

Opacity

Opacity tokens are available as static CGFloat variables in an extension on Opacity.

import EGDSTokensDefault

func setOpacity() {
  disabledView.backgroundColor = disabledView.backgroundColor.withAlphaComponent(Opacity.opacityDisabled())
  enabledView.backgroundColor = enabledView.backgroundColor.withAlphaComponent(Opacity.opacity100())
}

Elevation

UIKit

Elevation tokens are available under the Elevation struct as static methods returning a EGDSElevation. This can be applied using an UIView extension func with(elevation: EGDSElevation) -> Self.

import EGDSTokensDefault

func setElevation() {
  shadowedView.with(elevation: Elevation.elevation2())
  mapPinView.with(elevation: Elevation.mapPin())
}

SwiftUI

Elevation tokens can be applied through a custom view modifier func shadow(_ elevation: EGDSElevation) -> some View.

var body: some View {
  Rectangle()
    .shadow(.elevation1)
}

Gradient

UIKit

Gradient tokens are available within EGDSGradient. Translation to a view implementation is left to the client teams.

SwiftUI

Gradient tokens can be applied through a custom view modifier func background(_ gradient: EGDSGradient) -> some View.

var body: some View {
  Rectangle()
    .background(.gradient1)
}

Icon

UIKit

Icon tokens map to images stored in asset catalogs and are represented as static variables in the Icon struct. The UIImage representation is returned through the image property.

import EGDSTokensDefault

func setIcons() {
  zoomImageView.image = Icon.zoomIn.image
  wifiIcon.image = Icon.wifi.image
}

SwiftUI

Icon tokens are expressed in a nested struct Icons on Image.

var body: some View {
  VStack {
    Image.Icons.acUnit
    Text("Air conditioning")
  }
}

Mark

UIKit

Mark tokens map to images stored in asset catalogs and are represented as static variables in the Mark struct. The UIImage representation is returned through the image property.

import EGDSTokensDefault

func setMarks() {
  facebookLoginImageView.image = Mark.facebook.image
  googleLoginImageView.image = Mark.google.image
}

SwiftUI

Mark tokens are expressed in a nested struct Marks on Image.

var body: some View {
  HStack {
    Image.Marks.mod
    Text("Member only deal!")
  }
}

Missing (previously Offline Image)

UIKit

Missing tokens map to images stored in asset catalogs and are represented as static variables in the Missing struct. The UIImage representation is returned through the image property.

import EGDSTokensDefault

func setMissing() {
  imageView.image = Missing.avatarMissingFill.image
}

SwiftUI

Missing tokens are expressed in a nested struct Missings on Image.

var body: some View {
  HStack {
    Image.Missings.avatarMissingFill
    Text("User")
  }
}

Text Decoration

UIKit

Text decoration tokens are available as static enum TextDecorationType variables in an extension on TextDecoration. Implementation should be applied by client teams through the use of NSAttributedString.

SwiftUI

Text decoration tokens are available as can be applied to Text through the extension func decorate(_ textDecoration: TextDecorationType) -> some View

var body: some View {
  Text("Some underlined text")
    .decorate(.fontTextDecorationUnderline)
}

GitHub

link
Stars: 0
Last commit: 6 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API