A customizable Joystick made with SwiftUI

Related tags

UI SwiftUIJoystick
Overview

SwiftUIJoystick ๐Ÿ•น๏ธ

A customizable Joystick made with SwiftUI

Create your own Base and Thumb/Handle view using SwiftUI

SPM CocoaPods License: MIT

Features

  • Customizable background and thumb/foreground
  • Normal Joystick Example
  • Locking Joystick Example
  • Polar or XY Coordinates

#### View these examples to see how to make your own Joystick!

(View Code Example) (View Code Example) (View Code Example)

๐Ÿ“ฒ How to Install ๐Ÿ•น๏ธ

Swift Package Manager SPM

Add this repository's URL https://github.com/michael94ellis/SwiftUIJoystick

Cocoapods

Add this line to your podfile pod SwiftUIJoystick

๐Ÿ›  How to use

Example Code:

Ready to Copy, Paste, and Use (after install with SPM or Pods)

// An example Joystick
// Copy this example and modify it

import SwiftUI
import SwiftUIJoystick

public struct Joystick: View {
    
    /// The monitor object to observe the user input on the Joystick in XY or Polar coordinates
    @ObservedObject public var joystickMonitor: JoystickMonitor
    /// The width or diameter in which the Joystick will report values
    ///  For example: 100 will provide 0-100, with (50,50) being the origin
    private let dragDiameter: CGFloat
    /// Can be `.rect` or `.circle`
    /// Rect will allow the user to access the four corners
    /// Circle will limit Joystick it's radius determined by `dragDiameter / 2`
    private let shape: JoystickShape
    
    public init(monitor: JoystickMonitor, width: CGFloat, shape: JoystickShape = .rect) {
        self.joystickMonitor = monitor
        self.dragDiameter = width
        self.shape = shape
    }
    
    public var body: some View {
        VStack{
            JoystickBuilder(
                monitor: self.joystickMonitor,
                width: self.dragDiameter,
                shape: .rect,
                background: {
                    // Example Background
                    RoundedRectangle(cornerRadius: 8).fill(Color.red.opacity(0.5))
                },
                foreground: {
                    // Example Thumb
                    Circle().fill(Color.black)
                },
                locksInPlace: false)
        }
    }
}

๐Ÿ›  How to customize

Start by making a JoystickMonitor

You can subscribe to changes

Use a JoystickBuilder to build your own Joystick Controls' Background/Base and Thumb/Foreground views

Setup a Joystick Monitor

Setup the observer JoystickMonitor and width of the joystick

@StateObject private var monitor = JoystickMonitor(width: 100)
private let draggableDiameter: CGFloat = 100

Option 1

Create the Joystick using the Joystick Builder

Joystick Builder applies the joystickGestureRecognizer

JoystickBuilder(
    monitor: self.joystickMonitor,
    width: self.draggableDiameter,
    shape: .rect,
    background: {
        // Example Background
        RoundedRectangle(cornerRadius: 8).fill(Color.red.opacity(0.5))
    },
    foreground: {
        // Example Thumb
        Circle().fill(Color.black)
    },
    locksInPlace: false)

Option 2

Create your own Joystick tracking View with the JoystickRecognizer

Apply the joystickGestureRecognizer to any of your views to receive updates on the monitor

YourView()
    .joystickGestureRecognizer(monitor: self.joystickMonitor, 
                               width: self.width, 
                               shape: self.controlShape,
                               locksInPlace: self.locksInPlace)

Parameters

parameter type description default
monitor JoyStickMonitor ObservableObect that publishes the Joystick control's XY and Polar coordinates no
width CGFloat The width or diameter of the Joystick control no
Output values will be from 0-width
shape JostickShape The shape of the Joystick's hitbox area, rectangluar or circular Valid input: .rect or .circle no
background some View Any View type input can be put here to create a background for the Joystick no
foreground some View A View for the thumb or foreground of the Joystick no
locksInPlace Bool A bool to determine if the Joystick resets back to the center when release no

๐Ÿ‘จโ€๐Ÿ’ป Contributors

All issue reports, feature requests, pull requests and GitHub stars are welcomed and much appreciated.

To make a contribution

  1. Fork this repo
  2. Make your changes and test
  3. Make a Pull Request
  4. After merge update podspec version
  5. Push changes
  6. Create new version tag to match podspec version
  7. Update pods repo, run this command in the package directory 'pod trunk push SwiftUIJoystick.podspec'

โœ๏ธ Author

Michael Ellis

๐Ÿ“ƒ License

SwiftUIJoystick is available under the MIT license. See the LICENSE file for more info

You might also like...
Customizable School Timetable Library
Customizable School Timetable Library

JHTimeTable SwiftUI Customizable School TimeTable Library ์„ค์น˜ Swift Package Manager ์‚ฌ์šฉํ•˜๊ธฐ JHTimeTable๋ทฐ๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. JHTimeTable(lineColor : .secondary,

Fully customizable Facebook reactions like control
Fully customizable Facebook reactions like control

Reactions is a fully customizable control to give people more ways to share their reaction in a quick and easy way. Requirements โ€ข Usage โ€ข Installatio

Customizable CheckBox / RadioButton component for iOS
Customizable CheckBox / RadioButton component for iOS

GDCheckbox An easy to use CheckBox/Radio button component for iOS, with Attributes inspector support. Requirements Xcode 10+ Swift 5 iOS 9+ Installati

A beautiful radar view to show nearby items (users, restaurants, ...) with ripple animation, fully customizable
A beautiful radar view to show nearby items (users, restaurants, ...) with ripple animation, fully customizable

HGRippleRadarView Example To run the example project, clone the repo, and run pod install from the Example directory first. This project is inspired b

Easy to use, highly customizable gauge view
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types
A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

The CITPincode package provides a customizable pincode view
The CITPincode package provides a customizable pincode view

The CITPincode package provides a customizable pincode view. It includes an optional resend code button with a built-in cooldown and an optional divider to be placed anywhere between the cells.

A paging scroll view for SwiftUI, using internal SwiftUI components
A paging scroll view for SwiftUI, using internal SwiftUI components

PagingView A paging scroll view for SwiftUI, using internal SwiftUI components. This is basically the same as TabView in the paging mode with the inde

SwiftUI-Drawer - A bottom-up drawer in swiftUI
SwiftUI-Drawer - A bottom-up drawer in swiftUI

SwiftUI-Drawer A bottom-up drawer view. Contents Installation Examples Installat

Comments
  • shape: .circle has BUG in SwiftUI and iOS 15

    shape: .circle has BUG in SwiftUI and iOS 15

    when use

    JoystickBuilder(
                    monitor: self.joystickMonitor,
                    width: self.dragDiameter,
                    shape: .circle,
                    background: {
                        Circle().fill(Color.blue.opacity(0.9))
                            .frame(width: dragDiameter, height: dragDiameter)
                    },
                    foreground: {
                        Circle().fill(Color.black)
                            .frame(width: dragDiameter / 4, height: dragDiameter / 4)
                    },
                    locksInPlace: false)
    

    then then location point is error

    opened by c941010623 5
  • Multi-touch interference

    Multi-touch interference

    When I use the Demo,

    I hold the left hand with my left hand and click on the rectangle with my right hand,

    then the center point will stop.

    summary: If there is a click event in the rectangle while moving, the center point will stop.

    opened by c941010623 2
  • Can't add Swift Package on GUI

    Can't add Swift Package on GUI

    We can search but we can't add.

    Screen Shot 2022-09-25 at 15 35 09

    It can be added by writing directly in the package file.

    .package(url: "https://github.com/michael94ellis/SwiftUIJoystick", "1.5.0"..<"2.0.0")
    

    Release tag is stopped on an older version.

    Screen Shot 2022-09-25 at 15 41 19

    Please add the newest release tag on your github :)

    opened by crane-hiromu 1
Releases(1.0.3)
  • 1.0.3(Dec 5, 2021)

    Joystick library is ready to be consumed

    XY Coordinates Polar Coordinates Customizable Base and Handle/Thumb Ability to add recognizer, or create Joystick view with builder object

    Source code(tar.gz)
    Source code(zip)
Owner
Michaellis
Software Engineer, Mobile/Web Apps, IoT
Michaellis
We-split - A study app made using SwiftUI

We Split We Split is a study app made using SwiftUI, being part of 100 Days of S

Gabriel Pereira 1 Mar 16, 2022
:octocat:๐Ÿ’ง A slider widget with a popup bubble displaying the precise value selected. Swift UI library made by @Ramotion

FLUID SLIDER A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
๐Ÿ“Š A customizable gradient progress bar (UIProgressView).

GradientProgressBar A customizable gradient progress bar (UIProgressView). Inspired by iOS 7 Progress Bar from Codepen. Example To run the example pro

Felix M. 490 Dec 16, 2022
A customizable color picker for iOS in Swift

IGColorPicker is a fantastic color picker ?? written in Swift. Table of Contents Documentation Colors Style Other features Installation Example Gettin

iGenius 272 Dec 17, 2022
Modular and customizable Material Design UI components for iOS

Material Components for iOS Material Components for iOS (MDC-iOS) helps developers execute Material Design. Developed by a core team of engineers and

Material Components 4.6k Dec 29, 2022
Highly customizable Action Sheet Controller with Assets Preview written in Swift

PPAssetsActionController Play with me โ–ถ๏ธ ?? If you want to play with me, just tap here and enjoy! ?? ?? Show me ?? Try me ?? The easiest way to try me

Pavel Pantus 72 Feb 4, 2022
RangeSeedSlider provides a customizable range slider like a UISlider.

RangeSeekSlider Overview RangeSeekSlider provides a customizable range slider like a UISlider. This library is based on TomThorpe/TTRangeSlider (Objec

WorldDownTown 644 Dec 12, 2022
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

Ela Workshop 2.5k Jan 5, 2023
An easy to use UI component to help display a signal bar with an added customizable fill animation

TZSignalStrengthView for iOS Introduction TZSignalStrengthView is an easy to use UI component to help display a signal bar with an added customizable

TrianglZ LLC 22 May 14, 2022