Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New Arc support #106

Merged
merged 16 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc

- name: Enable Corepack
run: corepack enable
shell: bash

- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v4
uses: actions/cache@v3
with:
path: |
**/node_modules
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ on:
pull_request:
branches:
- main
merge_group:
types:
- checks_requested

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -27,31 +30,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage

verify:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Run expo doctor
run: yarn example doctor

build-library:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
Expand Down
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,15 @@ android/keystores/debug.keystore
# Expo
.expo/

# Turborepo
.turbo/

# generated by bob
lib/

# Example
example/ios
example/android
# React Native Codegen
ios/generated
android/generated

# Docs
.vercel
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.1.cjs

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
nmHoistingLimits: workspaces

nodeLinker: node-modules
nmHoistingLimits: workspaces

plugins:
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ The [example app](/example/) demonstrates usage of the library. You need to run

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/TrueSheetExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > TrueSheet`.
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/TrueSheetExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-true-sheet`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-true-sheet` under `Android`.

You can use various commands from the root directory to work with the project.

To start the packager:

```sh
yarn example start
```

To run the example app on Android:

```sh
Expand All @@ -43,7 +47,7 @@ To run the example app on iOS:
yarn example ios
```

Make sure your code passes TypeScript and ESLint. Run the following to verify:
Make sure your code passes TypeScript and ESLint. Run the following to verify and fix:

```sh
yarn tidy
Expand Down
7 changes: 6 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ buildscript {
}
}

def reactNativeArchitectures() {
def value = rootProject.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}
Expand Down Expand Up @@ -90,6 +95,6 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.google.android.material:material:1.11.0"
implementation 'com.google.android.material:material:1.12.0'
}

Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
maxScreenHeight = Utils.screenHeight(reactContext, edgeToEdge)
}

override fun getEdgeToEdgeEnabled(): Boolean {
return edgeToEdge || super.getEdgeToEdgeEnabled()
}
override fun getEdgeToEdgeEnabled(): Boolean = edgeToEdge || super.getEdgeToEdgeEnabled()

override fun onStart() {
super.onStart()
Expand Down Expand Up @@ -259,8 +257,8 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
})
}

fun setOnSizeChangeListener(listener: RootSheetView.OnSizeChangeListener) {
rootSheetView.setOnSizeChangeListener(listener)
fun setOnSizeChangeListener(listener: (w: Int, h: Int) -> Unit) {
rootSheetView.sizeChangeListener = listener
}

/**
Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.events.EventDispatcher
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.lodev09.truesheet.core.RootSheetView
import com.lodev09.truesheet.core.Utils
import com.lodev09.truesheet.events.ContainerSizeChangeEvent
import com.lodev09.truesheet.events.DismissEvent
import com.lodev09.truesheet.events.MountEvent
import com.lodev09.truesheet.events.PresentEvent
Expand Down Expand Up @@ -67,6 +69,10 @@ class TrueSheetView(context: Context) :

// Configure Sheet Dialog
sheetDialog.apply {
setOnSizeChangeListener { w, h ->
eventDispatcher?.dispatchEvent(ContainerSizeChangeEvent(surfaceId, id, Utils.toDIP(w), Utils.toDIP(h)))
}

// Setup listener when the dialog has been presented.
setOnShowListener {
registerKeyboardManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
import com.lodev09.truesheet.core.Utils
import com.lodev09.truesheet.events.ContainerSizeChangeEvent
import com.lodev09.truesheet.events.DismissEvent
import com.lodev09.truesheet.events.MountEvent
import com.lodev09.truesheet.events.PresentEvent
Expand All @@ -30,6 +31,7 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
.put(PresentEvent.EVENT_NAME, MapBuilder.of("registrationName", "onPresent"))
.put(DismissEvent.EVENT_NAME, MapBuilder.of("registrationName", "onDismiss"))
.put(SizeChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", "onSizeChange"))
.put(ContainerSizeChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", "onContainerSizeChange"))
.build()

@ReactProp(name = "edgeToEdge")
Expand Down
28 changes: 2 additions & 26 deletions android/src/main/java/com/lodev09/truesheet/core/RootSheetView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import android.annotation.SuppressLint
import android.content.Context
import android.view.MotionEvent
import android.view.View
import com.facebook.react.bridge.GuardedRunnable
import com.facebook.react.config.ReactFeatureFlags
import com.facebook.react.uimanager.JSPointerDispatcher
import com.facebook.react.uimanager.JSTouchDispatcher
import com.facebook.react.uimanager.RootView
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.uimanager.events.EventDispatcher
import com.facebook.react.views.view.ReactViewGroup

Expand All @@ -35,14 +33,10 @@ class RootSheetView(private val context: Context?) :

private val jSTouchDispatcher = JSTouchDispatcher(this)
private var jSPointerDispatcher: JSPointerDispatcher? = null
private var sizeChangeListener: OnSizeChangeListener? = null
public var sizeChangeListener: ((w: Int, h: Int) -> Unit)? = null

var eventDispatcher: EventDispatcher? = null

interface OnSizeChangeListener {
fun onSizeChange(width: Int, height: Int)
}

init {
if (ReactFeatureFlags.dispatchPointerEvents) {
jSPointerDispatcher = JSPointerDispatcher(this)
Expand All @@ -55,30 +49,12 @@ class RootSheetView(private val context: Context?) :
viewWidth = w
viewHeight = h
updateFirstChildView()

sizeChangeListener?.onSizeChange(w, h)
}

fun setOnSizeChangeListener(listener: OnSizeChangeListener) {
sizeChangeListener = listener
}

private fun updateFirstChildView() {
if (childCount > 0) {
hasAdjustedSize = false
val viewTag = getChildAt(0).id
reactContext.runOnNativeModulesQueueThread(
object : GuardedRunnable(reactContext) {
override fun runGuarded() {
val uiManager: UIManagerModule =
reactContext
.reactApplicationContext
.getNativeModule(UIManagerModule::class.java) ?: return

uiManager.updateNodeSize(viewTag, viewWidth, viewHeight)
}
}
)
sizeChangeListener?.let { it(viewWidth, viewHeight) }
} else {
hasAdjustedSize = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lodev09.truesheet.events

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.Event

// onContainerSizeChange
class ContainerSizeChangeEvent(surfaceId: Int, viewId: Int, private val width: Float, private val height: Float) :
Event<ContainerSizeChangeEvent>(surfaceId, viewId) {
override fun getEventName() = EVENT_NAME

override fun getEventData(): WritableMap {
val data = Arguments.createMap()
data.putDouble("width", width.toDouble())
data.putDouble("height", height.toDouble())

return data
}

companion object {
const val EVENT_NAME = "containerSizeChange"
}
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
presets: [['module:react-native-builder-bob/babel-preset', { modules: 'commonjs' }]],
}
25 changes: 25 additions & 0 deletions docs/docs/guides/edge2edge.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Enable edge-to-edge
description: Turning on edge-to-edge support for Android.
keywords: [bottom sheet edge-to-edge, edge-to-edge, android]
---

Yes! TrueSheet does support [`edge-to-edge`](https://developer.android.com/develop/ui/views/layout/edge-to-edge).

## How?

It's easy, just set [`edgeToEdge`](/reference/props#edgetoedge) to `true`.

```tsx {3}
const App = () => {
return (
<TrueSheet edgeToEdge={true}>
<View />
</TrueSheet>
)
}
```

## react-native-edge-to-edge

[`react-native-edge-to-edge`](https://github.com/zoontek/react-native-edge-to-edge) is a cool tiny package that lets you effortlessly enable `edge-to-edge` display for your app. Go check it out!
8 changes: 8 additions & 0 deletions docs/docs/reference/01-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ Shows a grabber (or handle). Native on IOS and styled `View` on Android.
| - | - | - | - |
| `boolean` | `true` | ✅ | ✅ |

### `edgeToEdge`

Supports edge-to-edge on Android. Turn this on if your app has it enabled.

| Type | Default | 🍎 | 🤖 |
| - | - | - | - |
| `boolean` | | | ✅ |

### `grabberProps`

Overrides the grabber props for android.
Expand Down
8 changes: 4 additions & 4 deletions example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
# bound in the template on Cocoapods with next React Native release.
gem 'cocoapods', '>= 1.13', '< 1.15'
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
gem 'xcodeproj', '< 1.26.0'
Loading
Loading