Skip to content

Instantly share code, notes, and snippets.

View mdjastrzebski's full-sized avatar
👋

Maciej Jastrzebski mdjastrzebski

👋
View GitHub Profile
@mdjastrzebski
mdjastrzebski / use-latest-prop-value.ts
Created August 14, 2025 13:11
use-latest-prop-value
/**
* Returns the latest value of given prop as a ref.
*
* This function allows treating given prop as a non-reactive value, that should be
* accessible in `useEffect` but does not trigger effect re-run.
*
* @param value - The prop value to be used as a ref
* @returns A ref that will always hold the latest value of the prop
*/
function useLatestPropRef<T>(value: T) {
import { useEffect } from 'react'
export class Timer {
name: string
lastTimestamp = 0
counts = new Map<string, number>()
durations = new Map<string, number>()
totalDuration = 0
totalCount = 0
import Flutter
import React
import UIKit
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
import Foundation
import React
// Source: https://github.com/TMisiukiewicz/react-native-host-example/blob/main/ios/ReactNativeHostExample/BridgeManager.swift
class BridgeManager: NSObject {
static let shared = BridgeManager()
var bridge: RCTBridge?
public func loadReactNative(launchOptions: [AnyHashable: Any]?) {
import Flutter
import React
import UIKit
/**
* Factory used by Flutter to create instances of FLReactView.
* @see https://docs.flutter.dev/platform-integration/ios/platform-views
*/
class FLReactViewFactory: NSObject, FlutterPlatformViewFactory {
private var messenger: FlutterBinaryMessenger
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Permissions used by RN .... -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<!-- Use our MainApplication class -->
<application
android:label="flutter_brownfield_app"
android:name=".MainApplication"
android:icon="@mipmap/ic_launcher"
package com.example.flutter_brownfield_app
import android.content.Intent
import android.view.KeyEvent
import com.facebook.react.ReactInstanceManager
import com.facebook.react.ReactNativeHost
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
import io.flutter.embedding.android.FlutterActivity
// ...
package com.example.flutter_brownfield_app
import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
class MainApplication: Application(), ReactApplication {
package com.example.flutter_brownfield_app
import android.content.Context
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
/**
* This is a Flutter PlatformViewFactory for creating instances of ReactView.
*/
package com.example.flutter_brownfield_app
import android.content.Context
import android.view.View
import com.facebook.react.ReactRootView
import io.flutter.plugin.platform.PlatformView
/**
* This view is used to embed React Native view directly in the native view hierarchy. It allows to
* mix and match Flutter and React Native views on one screen.