• Stars
    star
    297
  • Rank 140,075 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Open Source UI framework based on SwiftUI syntax and features, adding backwards compatibility.

logo

Build Pod Swift Package Manager Xcode iOS Swift

Open Source UI framework based on SwiftUI syntax and features, adding backwards compatibility.

Compatibility

  • Minimum iOS version: iOS 11.0
  • SwiftUI: Not interchangeable, but easy to share knowledge and migrate code both ways because of the high similarity in syntax.
  • UIKit: Compatible
  • Xcode: From Xcode 12
  • Platforms: iOS, iPadOS

Features

An overview of supported features can be seen here.

Installation

Swift Package Manager

Add Package url: https://github.com/rakutentech/AltSwiftUI

Cocoapods

Add the following to your Podfile:

pod 'AltSwiftUI'

Documentation

The complete source documentation contains functionality covered by AltSwiftUI including its unique features.

Usage

AltSwiftUI has some small differences to SwiftUI, where it handles certain features slightly differently and adds some missing features as well.

Getting Started

You can use a AltSwiftUI view hierarchy the same as in SwiftUI with AppDelegate or SceneDelegate.

Create a UIHostingController with a root View, and add it to the Window. Even though the names are similar, don't forget you should import AltSwiftUI instead of SwiftUI.

View Structure

The structure of a View is very similar to that of SwiftUI, with 2 key differences:

struct ExampleView: View {
	var viewStore = ViewValues() // Difference 1

	var body: View { // Difference 2
		Text("Welcome")
	}
}
  1. In order for the library to internally store generic properties of a view, you need to provide a viewStore property initialized with an empty ViewValues for each view you create.

  2. To target backwards compatibility, opaque return types (some View) which is supported from iOS 13 are not used. Instead, explicity return types are used.

State and Rendering

State management works the same way as in SwiftUI. When a view declares a property attributed with a property wrapper, it will update the view's body when that property's value changes.

@State private var exampleText = "Original text"
@ObservedObject var myModel = MyModel()

var body: View {
	VStack {
		Text(exampleText)
		Text(myModel.value)

		Divider()
			.padding(.vertical, 10)

		MyView($myModel.value) // Will update the view when 'MyView' updates the value
		Button("Update text") {
			exampleText = "Updated text" // Will update the view on button action
		}
	}
}

HStack and Multiline Texts

When using Text without lineLimit inside a HStack, make sure that all other elements have their width specified. Failing to do so may introduce undesired layouts.

Previews

To work with previews, there are 2 steps that need to be done:

  1. Write the preview code at the end of the file that contains the view(s) you want to preview. This works similar to SwiftUI, but the preview must also conform to AltPreviewProvider.
#if DEBUG && canImport(SwiftUI)

import protocol SwiftUI.PreviewProvider
import protocol AltSwiftUI.View

struct MyTextPreview : AltPreviewProvider, PreviewProvider {
    static var previewView: View {
        MyText()
    }
}

#endif
  1. Load the canvas: As of now (Xcode 12 beta), in order to display the preview Canvas, Xcode requires that Editor > Canvas is enabled and the current file contains this line: import SwiftUI. Since AltSwiftUI files won't contain import SwiftUI, you must go to a file that contains it in order to open the Canvas, and then pin it so that you can use it with AltSwiftUI previews. Adding import SwiftUI to your file temporally to open the Canvas is also an option.

Name conflicts for ObservableObject and Published

If you end up importing Foundation, either directly or by an umbrella framework, and try to use ObservableObject or Published, Xcode will have a hard time solving the ambiguity as Foundation currently also defines these types as typealias.

To solve this, you can either specify the type like AltSwiftUI.ObservableObject every time you use it, or you can explicitly import these 2 types, which will help resolve the ambiguity:

import Foundation
import protocol AltSwiftUI.ObservableObject
import class AltSwiftUI.Published

class MyClass: ObservableObject {
	@Published var property: Bool
}

High Performance

In AltSwiftUI, certain view modifiers can cause views to update with high performance. Modifiers in this category will indicate it in their function documentation. You can also refer to the list below:

  • List.contentOffset(_:): When the list updates the value of the binding
  • ScrollView.contentOffset(_:): When the scroll view updates the value of the binding
  • State changes that happen inside the closure of a DragGesture.onChanged().

High performance updates won't update children views of List or ScrollView types. It's generally recommended for view subhierarchies that you want to modify by high performance updates to be moved to a separate View while passing the state that causes the update as a Binding.

There are also a couple of modifiers you can use to alter the default behavior of high performance updates and increase performance gains. For more information see List.ignoreHighPerformance(), ScrollView.ignoreHighPerformance(), View.strictHighPerformanceUpdate() and View.skipHighPerformanceUpdate() in the documentation.

Additional Features

Some of AltSwiftUI additional features are listed in this section.

Geometry Listener

In addition to the GeometryReader view, AltSwiftUI also offers a View.geometryListener(_:) property. This property records changes in a view's frame and stores it in a binding, which can then be referenced in any part of the hierarchy.

Unlike GeometryReader, geometryListener doesn't generate a new view.

@State private var geometryProxy: GeometryProxy = .default

VStack {
	Text("Example")
		.geometryListener($geometryProxy)

	Color.red
		.frame(width: geometryProxy.size.width)
}

Interactive Pop Gesture

Interactive pop gesture is also enabled by default for navigation views that have custom left bar button items and regardless if they show the navigation bar or not. To set this behavior to false in all cases, set UIHostingController.isInteractivePopGestureEnabled to false.

Get Involved

If you find any issues or ideas of new features/improvements, you can submit an issue in GitHub.

We also welcome you to contribute by submitting a pull request.

For more information, see CONTRIBUTING.

License

MIT license. You can read the LICENSE for more details.

More Repositories

1

laravel-request-docs

Effortless API documentation tool for Laravel applications. Swagger alternative.
PHP
697
star
2

macos-push-tester

Native mac app for easily sending Apple APNs push notifications to iOS apps and FCM push notifications to Android apps.
Swift
115
star
3

terraform-provider-vsphere

[DEPRECATED] Terraform Custom Provider for VMware vSphere
Go
82
star
4

android-miniapp

Mini App SDK for Android Apps
Kotlin
76
star
5

r10

R10 is a library of interactive building blocks written in Elm and elm-ui that we use at Rakuten for creating user interfaces.
Elm
74
star
6

stAdv

Spatially Transformed Adversarial Examples with TensorFlow
Python
72
star
7

ios-miniapp

Mini App SDK for iOS Apps
Swift
44
star
8

PCT-Net-Image-Harmonization

Python
37
star
9

http-trinity

An Elm library that add extra features to the official elm/http library.
Elm
35
star
10

rakutentech.github.io

Rakuten Technology Page
Elm
32
star
11

ios-perftracking

Performance Tracking for iOS Apps
Objective-C
32
star
12

js-miniapp

Mini App SDK for JavaScript
JavaScript
29
star
13

jwkgen

Small command-line tool that generates asymmetric JSON Web Keys for the following algorithms and curves
Go
28
star
14

code-coverage-dashboard

Effective Code Coverage Tracking and Dashboard.
Go
27
star
15

cf-plugin-local-push

CloudFoundry plugin local push (deploying CF application on local docker container with buildpack)
Go
24
star
16

FAU_CVPR2021

Python
23
star
17

ios-rresultbuilders

Open Source DSL framework based on @resultbuilder and swift 5.4 compatibility
Swift
23
star
18

shibuya

JavaScript
23
star
19

cf-tools

Useful shell scripts for Cloud Foundry API v2
Shell
22
star
20

android-buildconfig

Shared (gradle) build configurations for Android and Java libraries
Groovy
21
star
21

spark-dirty-cat

Similarity encoding of dirty categorical variables (strings)
Scala
19
star
22

jwk-go

Library for parsing, encoding and generating JSON Web Keys in Go
Go
18
star
23

iOS-CreditCardReader

Camera based library for SwiftUI, AltSwiftUI and UIKit with lightweight and accurate credit card information detection, and fully customizable UI controls.
Swift
18
star
24

go-alertnotification

Go Package to notify app alerts to Email and MS teams using Webhook
Go
17
star
25

android-perftracking

Performance Tracking for Android Apps
Java
17
star
26

dorna_arm_ros

Python
15
star
27

BayesianExperiments.jl

Bayesian AB testing experiments.
Julia
14
star
28

data-science-platform

Democratize AI and Data Science. Rapidly develop and deploy models that drive business impact.
HTML
14
star
29

ios-remote-config

Remote Config for iOS Apps https://rakutentech.github.io/ios-remote-config/
Swift
13
star
30

kafka-firehose-nozzle

Forward logs from the Cloud Foundry Firehose to Apache Kafka
Go
13
star
31

docpub

DocPub is a command line utility for converting a folder structure of markdown files to HTML and uploading the result to Zendesk.
JavaScript
12
star
32

jndi-ldap-test-server

A minimalistic LDAP server that is meant for test vulnerability to JNDI+LDAP injection attacks in Java, especially CVE-2021-44228.
Go
11
star
33

kong-plugin-graphql-operation-whitelist

Whitelist operations that your consumers can send to your GraphQL server.
Lua
9
star
34

grapesjs-angular

GrapesJS Angular is an Angular wrapper around the GrapesJS library, it allows instantiating an Angular component containing the GrapesJS editor, as well as all of its managers accessible as Angular Injectables.
TypeScript
9
star
35

ByNet-SR

Pytorch Implementation of ICIP2017 Paper: “ByNet-SR: Image Super Resolution with a Bypass Connection Network”
Python
8
star
36

go-echo-kit

A collection of supportive functions for go-echo development
Go
8
star
37

engineering-blog

Sources of https://engineering.rakuten.today/
HTML
8
star
38

go-nozzle

Golang package for building CloudFoundry nozzle
Go
7
star
39

passenger-go-exporter

Passenger status monitoring agent for Prometheus.
Go
7
star
40

ios-buildconfig

Shared build configuration and tooling for iOS SDK development
JavaScript
7
star
41

android-sdkutils

Android library with utilities for SDK developers
Kotlin
7
star
42

github-enterprise-cookbook

Github Enterprise Chef Cookbook
Ruby
7
star
43

dotfiles-boshrelease

Perl
7
star
44

simple-autoscaler

Stateless autoscaler for Cloud Foundry applications
Go
6
star
45

arduino_blv640

Arduino-compatible driver library for the Oriental Motor BLV-Series motors
C++
6
star
46

ios-sdkutils

iOS library with utilities for SDK developers https://rakutentech.github.io/ios-sdkutils
Swift
6
star
47

android-manifest-config

Annotation processor that generates a class to lookup manifest metadata.
Java
6
star
48

Document-understanding

Python
6
star
49

android-inappmessaging

In-App Messaging SDK for Android Apps
Kotlin
6
star
50

kong-plugin-graphql-depth-limit

Limit the complexity of GraphQL queries based on their depth.
Lua
6
star
51

mobile-sdk-guidelines

Rakuten MAG SDK Team guidelines for developing mobile SDKs
6
star
52

cf-plugin-update-cli

CloudFoundry plugin update-cli (update cloudfoundry/cli to the latest version)
Go
5
star
53

dotconf-assist

dotconf-assist is a Web GUI and REST API Designed for Splunk Configuration Management
HTML
5
star
54

ios-inappmessaging

In-App Messaging SDK for iOS Apps https://rakutentech.github.io/ios-inappmessaging/
Swift
5
star
55

ios-crash-reporting

Crash Reporting for iOS Apps
Objective-C
5
star
56

plantuml-docker

Docker image for running a PlantUML server using the Rakuten theme
Dockerfile
5
star
57

parfind

A parallel, simplified version of find(1) for use on high-latency, highly-parallel file systems.
Go
5
star
58

go-watch-logs

Log monitoring tool, written in GO with God speeds.
Go
5
star
59

postgres-backup-boshrelease

Monit scripts adding backup jobs to cron
Shell
4
star
60

rmn-website

Rakuten Mindfulness Network website
CSS
4
star
61

nrp

Python
4
star
62

cf-metrics-refinery

Enrich and store in InfluxDB metrics of applications deployed on Cloud Foundry
Go
4
star
63

android-remote-config

Remote Config for Android apps
Kotlin
4
star
64

go-domo-api

Go
4
star
65

barcode

Super-lightweight barcode generation library for Android and iOS
Objective-C
4
star
66

pisah

Sentence Splitter Library (C++ port of pySBD)
C++
4
star
67

Rakuten-Unified-Memory

A Distributed Data Grid using User-Space Networking
C++
4
star
68

bosh-routing-release

BOSH release that changes the route table and the default gateway.
3
star
69

java-datastore

Simple local blob storage with support for encryption
Java
3
star
70

shared_rep

Python
3
star
71

hq

Python
3
star
72

chart-synthesizer

Python
3
star
73

android-crash-reporting

Crash Reporting for Android devices
Java
3
star
74

android-analytics

Records user activity and automatically sends tracking events to an analytics cloud service.
3
star
75

magga

Open Source Mobile Platform for Learning
2
star
76

node-alertnotification

JavaScript
2
star
77

api-automation-tools

Python
2
star
78

MTL_onlineKD_WACV2023

Python
2
star
79

redis-twemproxy-agent

Ruby
2
star
80

MathSensei

Python
2
star
81

rbot

Rakuten Robotics Base Toolkit (Rbot)
C++
2
star
82

StateDesignEngine

JavaScript
1
star
83

leofs_docs

CSS
1
star
84

jenkins_support_tool

PHP
1
star
85

ui-automation-tools-mbt

Python
1
star
86

esquisite

A library of exquisite helpers and utilities for ES apps.
JavaScript
1
star
87

mimo

Chef cookbook for Mimo https://github.com/shutterfly/Mimo
Ruby
1
star
88

homebrew-tap

Homebrew tap for Rakuten Open Source apps
Ruby
1
star
89

ios-analytics-framework

SDK that records user activity and automatically sends tracking events to an analytics cloud service.
Ruby
1
star
90

chef_java_libs

Java Libraries Chef Cookbook
Ruby
1
star
91

cocoapods-cordova-plugins

Ruby
1
star
92

embed-position-bias

Jupyter Notebook
1
star
93

gradle-cordova-plugins

Groovy
1
star
94

causalkit

Rust
1
star