Skip to content

Instantly share code, notes, and snippets.

View nbhasin2's full-sized avatar

Nishant Bhasin nbhasin2

View GitHub Profile
@nbhasin2
nbhasin2 / metal5.swift
Created March 13, 2025 05:27
metal5.swift
struct CircleMetalView: UIViewRepresentable {
func makeUIView(context: Context) -> MTKView {
let metalView = MTKView()
metalView.device = MTLCreateSystemDefaultDevice()
metalView.framebufferOnly = false
metalView.colorPixelFormat = .bgra8Unorm
metalView.delegate = context.coordinator
return metalView
}
@nbhasin2
nbhasin2 / metal4.swift
Last active March 13, 2025 05:26
metal4.swift
class CircleRenderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
self.device = device
self.commandQueue = device.makeCommandQueue()
let library = device.makeDefaultLibrary()
@nbhasin2
nbhasin2 / metal3.metal
Last active April 2, 2025 05:36
metal3.metal
#include <metal_stdlib>
using namespace metal;
// Basic vertex shader outputs position only
vertex float4 basic_vertex(uint vertexID [[vertex_id]]) {
// Define vertices for a full-screen quad
float2 positions[4] = {
{-1, -1}, // Bottom-left
{ 1, -1}, // Bottom-right
{-1, 1}, // Top-left
@nbhasin2
nbhasin2 / metal2.swift
Created March 13, 2025 05:07
metal2.swift
struct BasicMetalView: UIViewRepresentable {
func makeUIView(context: Context) -> MTKView {
let metalView = MTKView()
metalView.device = MTLCreateSystemDefaultDevice()
metalView.framebufferOnly = false
metalView.colorPixelFormat = .bgra8Unorm
metalView.delegate = context.coordinator
return metalView
}
@nbhasin2
nbhasin2 / Renderer1.swift
Last active April 2, 2025 05:35
Renderer1.swift
import MetalKit
import SwiftUI
class Renderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
super.init()
@nbhasin2
nbhasin2 / gist:373c962a7569c2d3a0cc237476894ec1
Last active February 3, 2025 22:37
SwiftUI in Firefox iOS

SwiftUI in Firefox iOS

Decision Tree for SwiftUI vs. UIKit

The following decision tree should be used to determine whether to use SwiftUI or UIKit for new and existing components:
SwiftUI Decision Tree

Existing Implementations (SwiftUI)

The following list shows components that are implemented using SwiftUI and some that have future potential for SwiftUI conversion.

| Component | Type |

@nbhasin2
nbhasin2 / temp_exp.json
Last active January 8, 2024 20:57
temp_exp.json
{
"data": [
{
"appId": "org.mozilla.ios.Firefox",
"appName": "firefox_ios",
"application": "org.mozilla.ios.Firefox",
"arguments": {},
"branches": [
{
"feature": {
@nbhasin2
nbhasin2 / cc_temp.json
Last active January 8, 2024 20:53
cc_temp
{
"data": [
{
"appId": "org.mozilla.ios.Firefox",
"appName": "firefox_ios",
"application": "org.mozilla.ios.Firefox",
"arguments": {},
"branches": [
{
"feature": {
@nbhasin2
nbhasin2 / NavHandlerExample.swift
Last active April 3, 2023 01:44
NavHandlerExample
var body: some View {
NavHandler {
List(cars) { car in
NavigationLink(car.rawValue) {
CarDetailView(car: car)
}
}
}
}
struct NavHandler<Content>: View where Content: View {
@ViewBuilder var content: () -> Content
var body: some View {
if #available(iOS 16, *) {
NavigationStack(root: content)
} else {
NavigationView(content: content)
}
}