|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.react.modules.devtoolsruntimesettings |
| 9 | + |
| 10 | +import com.facebook.fbreact.specs.NativeReactDevToolsRuntimeSettingsModuleSpec |
| 11 | +import com.facebook.jni.annotations.DoNotStripAny |
| 12 | +import com.facebook.react.bridge.Arguments |
| 13 | +import com.facebook.react.bridge.ReactApplicationContext |
| 14 | +import com.facebook.react.bridge.ReadableMap |
| 15 | +import com.facebook.react.bridge.WritableMap |
| 16 | +import com.facebook.react.module.annotations.ReactModule |
| 17 | + |
| 18 | +private class Settings { |
| 19 | + var shouldReloadAndProfile: Boolean = false |
| 20 | + var recordChangeDescriptions: Boolean = false |
| 21 | +} |
| 22 | + |
| 23 | +@DoNotStripAny |
| 24 | +@ReactModule(name = NativeReactDevToolsRuntimeSettingsModuleSpec.NAME) |
| 25 | +public class ReactDevToolsRuntimeSettingsModule(reactContext: ReactApplicationContext?) : |
| 26 | + NativeReactDevToolsRuntimeSettingsModuleSpec(reactContext) { |
| 27 | + |
| 28 | + // static to persist across Turbo Module reloads |
| 29 | + private companion object { |
| 30 | + private val settings = Settings() |
| 31 | + } |
| 32 | + |
| 33 | + override fun setReloadAndProfileConfig(map: ReadableMap) { |
| 34 | + if (map.hasKey("shouldReloadAndProfile")) { |
| 35 | + settings.shouldReloadAndProfile = map.getBoolean("shouldReloadAndProfile") |
| 36 | + } |
| 37 | + if (map.hasKey("recordChangeDescriptions")) { |
| 38 | + settings.recordChangeDescriptions = map.getBoolean("recordChangeDescriptions") |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + override fun getReloadAndProfileConfig(): WritableMap { |
| 43 | + val map = Arguments.createMap() |
| 44 | + map.putBoolean("shouldReloadAndProfile", settings.shouldReloadAndProfile) |
| 45 | + map.putBoolean("recordChangeDescriptions", settings.recordChangeDescriptions) |
| 46 | + return map |
| 47 | + } |
| 48 | +} |
0 commit comments