From 79c4bc1e152508b09bf60502b3453e8d131976d3 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Sun, 20 Jul 2025 13:00:36 +0100 Subject: [PATCH] [DoNotCommit] Helloworld example of pure swift TM --- private/helloworld/App.tsx | 83 +++++++++++++------ private/helloworld/Gemfile | 1 + private/helloworld/Gemfile.lock | 3 +- .../ios/HelloWorld-Bridging-Header.h | 8 ++ .../ios/HelloWorld.xcodeproj/project.pbxproj | 54 +++++++++--- private/helloworld/ios/HelloWorld/Info.plist | 3 +- .../NativeLocalStorage.swift | 34 ++++++++ .../RCTNativeLocalStorageModuleProvider.h | 17 ++++ .../RCTNativeLocalStorageModuleProvider.mm | 23 +++++ private/helloworld/package.json | 15 +++- .../helloworld/specs/NativeLocalStorage.ts | 13 +++ 11 files changed, 212 insertions(+), 42 deletions(-) create mode 100644 private/helloworld/ios/HelloWorld-Bridging-Header.h create mode 100644 private/helloworld/ios/NativeLocalStorage/NativeLocalStorage.swift create mode 100644 private/helloworld/ios/NativeLocalStorage/RCTNativeLocalStorageModuleProvider.h create mode 100644 private/helloworld/ios/NativeLocalStorage/RCTNativeLocalStorageModuleProvider.mm create mode 100644 private/helloworld/specs/NativeLocalStorage.ts diff --git a/private/helloworld/App.tsx b/private/helloworld/App.tsx index 09f7928a852..f56dc1b9f3d 100644 --- a/private/helloworld/App.tsx +++ b/private/helloworld/App.tsx @@ -1,42 +1,73 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - */ - -import * as React from 'react'; +import React from 'react'; import { SafeAreaView, - ScrollView, - StatusBar, StyleSheet, Text, - View, - useColorScheme, + TextInput, + Button, } from 'react-native'; -function App(): React.ReactNode { - const isDarkMode = useColorScheme() === 'dark'; +import NativeLocalStorage from './specs/NativeLocalStorage'; + +const EMPTY = ''; + +function App(): React.JSX.Element { + const [value, setValue] = React.useState(null); + + const [editingValue, setEditingValue] = React.useState< + string | null + >(null); + + React.useEffect(() => { + const storedValue = NativeLocalStorage?.getItem('myKey'); + setValue(storedValue ?? ''); + }, []); + + function saveValue() { + NativeLocalStorage?.setItem(editingValue ?? EMPTY, 'myKey'); + setValue(editingValue); + } + + function clearAll() { + NativeLocalStorage?.clear(); + setValue(''); + } + + function deleteValue() { + NativeLocalStorage?.removeItem('myKey'); + setValue(''); + } return ( - - - - - Hello, World! - - + + + Current stored value is: {value ?? 'No Value'} + + +