Skip to content

Commit

Permalink
Add fluent-ui-react-native controls
Browse files Browse the repository at this point in the history
- Allows use of their Button type
- Required importing SVG (see microsoft/fluentui-react-native#2613)
- Which in turn requires importing the Win2D nuget
- Also required switching to classic runtime (see microsoft/fluentui-react-native#1891)
  • Loading branch information
chrisglein committed Mar 31, 2023
1 parent 5ee0c30 commit b890ae6
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 25 deletions.
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: [['module:metro-react-native-babel-preset', {useTransformReactJSXExperimental:true}]],
plugins: [['@babel/plugin-transform-react-jsx', { runtime: 'classic' }]]
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react": "18.2.0",
"react-native": "0.71.0",
"react-native-markdown-display": "^7.0.0-alpha.2",
"react-native-svg": "^13.9.0",
"react-native-syntax-highlighter": "^2.1.0",
"react-native-windows": "0.71.1"
},
Expand Down
17 changes: 9 additions & 8 deletions src/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {
Button,
ScrollView,
TextInput,
View,
Expand All @@ -15,6 +14,7 @@ import {
} from './Feedback';
import { PopupsContext } from './Popups';
import { HoverButton } from './Controls';
import { ButtonV1 as Button } from '@fluentui/react-native';

enum ChatSource {
Human,
Expand Down Expand Up @@ -86,13 +86,15 @@ function ChatEntry({submit, defaultText, clearConversation}: ChatEntryProps): JS
onSubmitEditing={submitValue}
value={defaultText ?? value}/>
<Button
appearance='primary'
accessibilityLabel='Submit prompt'
title="Submit"
onPress={submitValue}/>
onClick={submitValue}>Submit</Button>
<Button
accessibilityLabel='Clear conversation'
title="💣"
onPress={clearConversation}/>
icon={{ fontSource: { fontFamily: 'Segoe MDL2 Assets', codepoint: 0xE74D, fontSize: 20 } }}
iconOnly={true}
tooltip='Clear conversation'
onClick={clearConversation}></Button>
</View>
);
}
Expand Down Expand Up @@ -170,11 +172,10 @@ function Chat({entries, humanText, onPrompt, clearConversation}: ChatProps): JSX
<View style={{alignSelf: 'center'}}>
<Button
accessibilityLabel="Regenerate response"
title="🔁 Regenerate response"
onPress={() => {
onClick={() => {
// Clear the response for the last entry
chatHistory.modifyResponse(entries.length - 1, {responses: undefined});
}}/>
}}>🔁 Regenerate response</Button>
</View>
}
</View>
Expand Down
14 changes: 7 additions & 7 deletions src/Popups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'react-native';
import {Popup} from 'react-native-windows';
import {StylesContext} from './Styles';
import { Button, IFocusable } from '@fluentui/react-native';
import { ButtonV1 as Button } from '@fluentui/react-native';

type PopupsContextType = {
showAbout: boolean,
Expand All @@ -32,12 +32,12 @@ type DialogFrameType = PropsWithChildren<{
function DialogFrame({children, show, close, isLightDismissEnabled, titleIcon, titleIconStyle, title, buttons}: DialogFrameType) {
const styles = React.useContext(StylesContext);

const populatedButtons = buttons ?? [<Button
accessibilityLabel='OK'
title="OK"
onPress={() => {
close();
}}/>];
const populatedButtons = buttons ?? [
<Button
appearance='primary'
onClick={() => {
close();
}}>OK</Button>];
const buttonList = populatedButtons.map((button, index) => <View key={index}>{button}</View>);

return (
Expand Down
14 changes: 5 additions & 9 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import {
Button,
Switch,
Text,
TextInput,
View,
Expand All @@ -18,6 +16,7 @@ import {StylesContext} from './Styles';
import {Picker} from '@react-native-picker/picker';
import {ChatScriptNames} from './ChatScript';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { ButtonV1 as Button } from '@fluentui/react-native';

const settingsKey = 'settings';

Expand Down Expand Up @@ -162,17 +161,14 @@ function SettingsPopup({show, close}: SettingsPopupProps): JSX.Element {

const buttons = [
<Button
accessibilityLabel="OK"
title="OK"
onPress={() => {
save();
}}/>,
}}>OK</Button>,
<Button
accessibilityLabel="Cancel"
title="Cancel"
onPress={() => {
appearance='primary'
onClick={() => {
cancel();
}}/>
}}>Cancel</Button>
];

return (
Expand Down
14 changes: 14 additions & 0 deletions windows/artificialChat.sln
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Clipboard", "..\node_module
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReactNativeAsyncStorage", "..\node_modules\@react-native-async-storage\async-storage\windows\ReactNativeAsyncStorage\ReactNativeAsyncStorage.vcxproj", "{4855D892-E16C-404D-8286-0089E0F7F9C4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RNSVG", "..\node_modules\react-native-svg\windows\RNSVG\RNSVG.vcxproj", "{7ACF84EC-EFBA-4043-8E14-40B159508902}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -165,6 +167,18 @@ Global
{4855D892-E16C-404D-8286-0089E0F7F9C4}.Release|x64.Build.0 = Release|x64
{4855D892-E16C-404D-8286-0089E0F7F9C4}.Release|x86.ActiveCfg = Release|Win32
{4855D892-E16C-404D-8286-0089E0F7F9C4}.Release|x86.Build.0 = Release|Win32
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|ARM64.ActiveCfg = Debug|ARM64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|ARM64.Build.0 = Debug|ARM64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|x64.ActiveCfg = Debug|x64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|x64.Build.0 = Debug|x64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|x86.ActiveCfg = Debug|Win32
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Debug|x86.Build.0 = Debug|Win32
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|ARM64.ActiveCfg = Release|ARM64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|ARM64.Build.0 = Release|ARM64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|x64.ActiveCfg = Release|x64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|x64.Build.0 = Release|x64
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|x86.ActiveCfg = Release|Win32
{7ACF84EC-EFBA-4043-8E14-40B159508902}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 5 additions & 0 deletions windows/artificialChat/AutolinkedNativeModules.g.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// Includes from @react-native-picker/picker
#include <winrt/ReactNativePicker.h>

// Includes from react-native-svg
#include <winrt/RNSVG.h>

namespace winrt::Microsoft::ReactNative
{

Expand All @@ -23,6 +26,8 @@ void RegisterAutolinkedNativeModulePackages(winrt::Windows::Foundation::Collecti
packageProviders.Append(winrt::NativeClipboard::ReactPackageProvider());
// IReactPackageProviders from @react-native-picker/picker
packageProviders.Append(winrt::ReactNativePicker::ReactPackageProvider());
// IReactPackageProviders from react-native-svg
packageProviders.Append(winrt::RNSVG::ReactPackageProvider());
}

}
4 changes: 4 additions & 0 deletions windows/artificialChat/AutolinkedNativeModules.g.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
<ProjectReference Include="$(ProjectDir)..\..\node_modules\@react-native-picker\picker\windows\ReactNativePicker\ReactNativePicker.vcxproj">
<Project>{bedcc600-4541-41f2-aa46-9e058202b6ad}</Project>
</ProjectReference>
<!-- Projects from react-native-svg -->
<ProjectReference Include="$(ProjectDir)..\..\node_modules\react-native-svg\windows\RNSVG\RNSVG.vcxproj">
<Project>{7acf84ec-efba-4043-8e14-40b159508902}</Project>
</ProjectReference>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions windows/artificialChat/artificialChat.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
</ItemGroup>
<ItemGroup>
<None Include="artificialChat_TemporaryKey.pfx" />
<None Include="packages.config" />
<None Include="PropertySheet.props" />
<Text Include="readme.txt">
<DeploymentContent>false</DeploymentContent>
Expand All @@ -217,6 +218,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ReactNativeWindowsTargets">
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets')" />
<Import Project="..\packages\Win2D.uwp.1.27.0-preview2\build\native\Win2D.uwp.targets" Condition="Exists('..\packages\Win2D.uwp.1.27.0-preview2\build\native\Win2D.uwp.targets')" />
</ImportGroup>
<Target Name="EnsureReactNativeWindowsTargets" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand All @@ -225,4 +227,10 @@
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.props'))" />
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets'))" />
</Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Win2D.uwp.1.27.0-preview2\build\native\Win2D.uwp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Win2D.uwp.1.27.0-preview2\build\native\Win2D.uwp.targets'))" />
</Target>
</Project>
5 changes: 5 additions & 0 deletions windows/artificialChat/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Win2D.uwp" version="1.27.0-preview2" targetFramework="native"/>
<package id="Microsoft.UI.Xaml" version="2.7.0" targetFramework="native"/>
</packages>
84 changes: 84 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3076,6 +3076,11 @@ bl@^4.1.0:
inherits "^2.0.4"
readable-stream "^3.4.0"

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down Expand Up @@ -3548,6 +3553,17 @@ css-color-keywords@^1.0.0:
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
integrity sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==

css-select@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-5.1.0.tgz#b8ebd6554c3637ccc76688804ad3f6a6fdaea8a6"
integrity sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==
dependencies:
boolbase "^1.0.0"
css-what "^6.1.0"
domhandler "^5.0.2"
domutils "^3.0.1"
nth-check "^2.0.1"

css-to-react-native@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-3.2.0.tgz#cdd8099f71024e149e4f6fe17a7d46ecd55f1e32"
Expand All @@ -3557,6 +3573,19 @@ css-to-react-native@^3.0.0:
css-color-keywords "^1.0.0"
postcss-value-parser "^4.0.2"

css-tree@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-1.1.3.tgz#eb4870fb6fd7707327ec95c2ff2ab09b5e8db91d"
integrity sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==
dependencies:
mdn-data "2.0.14"
source-map "^0.6.1"

css-what@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-6.1.0.tgz#fb5effcf76f1ddea2c81bdfaa4de44e79bac70f4"
integrity sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==

csstype@^3.0.2:
version "3.1.1"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9"
Expand Down Expand Up @@ -3732,6 +3761,36 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dom-serializer@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-2.0.0.tgz#e41b802e1eedf9f6cae183ce5e622d789d7d8e53"
integrity sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==
dependencies:
domelementtype "^2.3.0"
domhandler "^5.0.2"
entities "^4.2.0"

domelementtype@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.3.0.tgz#5c45e8e869952626331d7aab326d01daf65d589d"
integrity sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==

domhandler@^5.0.1, domhandler@^5.0.2:
version "5.0.3"
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-5.0.3.tgz#cc385f7f751f1d1fc650c21374804254538c7d31"
integrity sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==
dependencies:
domelementtype "^2.3.0"

domutils@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-3.0.1.tgz#696b3875238338cb186b6c0612bd4901c89a4f1c"
integrity sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==
dependencies:
dom-serializer "^2.0.0"
domelementtype "^2.3.0"
domhandler "^5.0.1"

ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
Expand Down Expand Up @@ -3771,6 +3830,11 @@ end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"

entities@^4.2.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-4.4.0.tgz#97bdaba170339446495e653cfd2db78962900174"
integrity sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==

entities@~2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
Expand Down Expand Up @@ -5975,6 +6039,11 @@ markdown-it@^10.0.0:
mdurl "^1.0.1"
uc.micro "^1.0.5"

mdn-data@2.0.14:
version "2.0.14"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.14.tgz#7113fc4281917d63ce29b43446f701e68c25ba50"
integrity sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==

mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
Expand Down Expand Up @@ -6599,6 +6668,13 @@ npm-run-path@^4.0.0, npm-run-path@^4.0.1:
dependencies:
path-key "^3.0.0"

nth-check@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-2.1.1.tgz#c9eab428effce36cd6b92c924bdb000ef1f1ed1d"
integrity sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==
dependencies:
boolbase "^1.0.0"

nullthrows@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/nullthrows/-/nullthrows-1.1.1.tgz#7818258843856ae971eae4208ad7d7eb19a431b1"
Expand Down Expand Up @@ -7185,6 +7261,14 @@ react-native-markdown-display@^7.0.0-alpha.2:
prop-types "^15.7.2"
react-native-fit-image "^1.5.5"

react-native-svg@^13.9.0:
version "13.9.0"
resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-13.9.0.tgz#8df8a690dd00362601f074dec5d3a86dd0f99c7f"
integrity sha512-Ey18POH0dA0ob/QiwCBVrxIiwflhYuw0P0hBlOHeY4J5cdbs8ngdKHeWC/Kt9+ryP6fNoEQ1PUgPYw2Bs/rp5Q==
dependencies:
css-select "^5.1.0"
css-tree "^1.1.3"

react-native-syntax-highlighter@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-native-syntax-highlighter/-/react-native-syntax-highlighter-2.1.0.tgz#66bdb2cedbe938b291bfe415e5d72d0c275ce353"
Expand Down

0 comments on commit b890ae6

Please sign in to comment.