-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(Shared): Migrate Image #882
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
Closed
kevinvangelder
wants to merge
35
commits into
microsoft:master
from
infinitered:shared-project-image
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
88370b1
Syncing with upstream
pre10der89 f84414a
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 03ced95
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 06f707e
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 4a27072
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 95e155d
Adding shell/MainReactPackage to ReactNative.Net46
pre10der89 a468c89
Adding Playground.Net46 WPF application with basic ReactNative integr…
pre10der89 d0665a7
Added a bootstrapper for initializing the ReactPage and the applicati…
pre10der89 32a32a8
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 0182bf4
Reverting the Examples to the previous version
pre10der89 c14d959
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 08f2fed
* Restyling Net46 RedBoxDialog and ProgressDialog to fit WPF styling...
pre10der89 f9f14d2
Merge branch 'master' of https://github.com/pre10der89/react-native-w…
pre10der89 20e5573
* Moving Progress Design Data to its own file... Renaming existing de…
pre10der89 6abdbd4
* Implemented a mouse accelerator to invoke the developer support fea…
pre10der89 826f389
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 d882809
Merge branch 'master' of https://github.com/pre10der89/react-native-w…
pre10der89 e21fade
* Set RootView to be Focusable and its FocusVisualStyle to null and e…
pre10der89 f30bd7f
Fixing random issues everywhere...
pre10der89 d3ca586
Fixing Touch point issues
pre10der89 7cdbd8b
Final debugging of Playground.Net46 App
pre10der89 6867174
code cleanup
kevinvangelder de556c9
upgraded nuget package and implemented websocket module
kevinvangelder 63f0152
Merge branch 'master' of https://github.com/ReactWindows/react-native…
pre10der89 496aebc
Merge branch 'master' of https://github.com/pre10der89/react-native-w…
pre10der89 4c2514f
Merge branch 'playground-net46' of https://github.com/pre10der89/reac…
pre10der89 0bb3309
Merge remote-tracking branch 'upstream2/master' into playground-net46
kevinvangelder 10ae03a
Merge branch 'playground-net46' of https://github.com/pre10der89/reac…
kevinvangelder 42ea822
Fixing failing tests on dispatcher null reference
pre10der89 e9ae10d
Migrated WebSocketModuleTests to Shared.Tests, Fixed Net46 WebSocketM…
pre10der89 5baa027
Merge branch 'playground-net46' of https://github.com/pre10der89/reac…
kevinvangelder 680ad10
migrated image component
kevinvangelder 094b92f
merged from upstream/master with playground.net46 changes
kevinvangelder 34eaf63
removed unnecessary files and fixed one missed merge conflict
kevinvangelder 655b654
cleanup to match feedback on initial Playground.Net46 PR
kevinvangelder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule Examples
updated
from fc20d0 to be5c02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
ReactWindows/ReactNative.Net46/Modules/Image/BitmapImageHelpers.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Reactive; | ||
| using System.Reactive.Concurrency; | ||
| using System.Reactive.Linq; | ||
| using System.Runtime.InteropServices.WindowsRuntime; | ||
| using System.Threading.Tasks; | ||
| using System.Windows; | ||
| using System.Windows.Media; | ||
| using System.Windows.Media.Imaging; | ||
| using static System.FormattableString; | ||
|
|
||
| namespace ReactNative.Modules.Image | ||
| { | ||
| static class BitmapImageHelpers | ||
| { | ||
| public static bool IsBase64Uri(string uri) | ||
| { | ||
| if (uri == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(uri)); | ||
| } | ||
|
|
||
| return uri.StartsWith("data:"); | ||
| } | ||
|
|
||
| public static Stream GetStreamAsync(string uri) | ||
| { | ||
| if (uri == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(uri)); | ||
| } | ||
|
|
||
| if (IsBase64Uri(uri)) | ||
| { | ||
| var decodedData = Convert.FromBase64String(uri.Substring(uri.IndexOf(",") + 1)); | ||
| return new MemoryStream(decodedData); | ||
| } | ||
| else | ||
| { | ||
| var uriValue = default(Uri); | ||
| if (!Uri.TryCreate(uri, UriKind.Absolute, out uriValue)) | ||
| { | ||
| throw new ArgumentOutOfRangeException(nameof(uri), Invariant($"Invalid URI '{uri}' provided.")); | ||
| } | ||
|
|
||
| var streamReference = new StreamReader(WebRequest.Create(uri).GetResponse().GetResponseStream()); //RandomAccessStreamReference.CreateFromUri(uriValue); | ||
| return streamReference.BaseStream; | ||
| } | ||
| } | ||
|
|
||
| public static IObservable<ImageStatusEventData> GetStreamLoadObservable(this BitmapImage image) | ||
| { | ||
| return image.GetOpenedObservable() | ||
| .Merge(image.GetFailedObservable(), Scheduler.Default) | ||
| .StartWith(new ImageStatusEventData(ImageLoadStatus.OnLoadStart)); | ||
| } | ||
|
|
||
| public static IObservable<ImageStatusEventData> GetUriLoadObservable(this BitmapImage image) | ||
| { | ||
| return Observable.Merge( | ||
| Scheduler.Default, | ||
| image.GetDownloadingObservable(), | ||
| image.GetOpenedObservable(), | ||
| image.GetFailedObservable()); | ||
| } | ||
|
|
||
| private static IObservable<ImageStatusEventData> GetOpenedObservable(this BitmapImage image) | ||
| { | ||
| return Observable.FromEventPattern<EventHandler, RoutedEventArgs>( | ||
| h => image.DownloadCompleted += h, | ||
| h => image.DownloadCompleted -= h) | ||
| .Select(args => | ||
| { | ||
| var bitmapImage = args.Sender as BitmapImage; | ||
| if (bitmapImage != null) | ||
| { | ||
| return new ImageStatusEventData( | ||
| ImageLoadStatus.OnLoad, | ||
| new ImageMetadata( | ||
| image.UriSource?.AbsoluteUri, | ||
| image.PixelWidth, | ||
| image.PixelHeight)); | ||
| } | ||
| else | ||
| { | ||
| return new ImageStatusEventData(ImageLoadStatus.OnLoad); | ||
| } | ||
| }) | ||
| .Take(1) | ||
| .Concat(Observable.Return(new ImageStatusEventData(ImageLoadStatus.OnLoadEnd))); | ||
| } | ||
|
|
||
| private static IObservable<ImageStatusEventData> GetFailedObservable(this BitmapImage image) | ||
| { | ||
| return Observable.FromEventPattern<EventHandler<System.Windows.Media.ExceptionEventArgs>, ExceptionRoutedEventArgs>( | ||
| h => image.DownloadFailed += h, | ||
| h => image.DownloadFailed -= h) | ||
| .Select<EventPattern<ExceptionRoutedEventArgs>, ImageStatusEventData>(pattern => | ||
| { | ||
| throw new InvalidOperationException(pattern.EventArgs.ErrorException.Message); | ||
| }); | ||
| } | ||
|
|
||
| private static IObservable<ImageStatusEventData> GetDownloadingObservable(this BitmapImage image) | ||
| { | ||
| return Observable.FromEventPattern<EventHandler<DownloadProgressEventArgs>, DownloadProgressChangedEventArgs>( | ||
| h => image.DownloadProgress += h, | ||
| h => image.DownloadProgress -= h) | ||
| .Take(1) | ||
| .Select(_ => new ImageStatusEventData(ImageLoadStatus.OnLoadStart)); | ||
| } | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
ReactWindows/ReactNative.Net46/Modules/Image/ImageLoaderModule.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using Newtonsoft.Json.Linq; | ||
| using ReactNative.Bridge; | ||
| using System; | ||
| using System.Reactive.Linq; | ||
| using System.Windows.Media.Imaging; | ||
|
|
||
| namespace ReactNative.Modules.Image | ||
| { | ||
| class ImageLoaderModule : NativeModuleBase | ||
| { | ||
| private const string ErrorInvalidUri = "E_INVALID_URI"; | ||
| private const string ErrorPrefetchFailure = "E_PREFETCH_FAILURE"; | ||
| private const string ErrorGetSizeFailure = "E_GET_SIZE_FAILURE"; | ||
|
|
||
| public override string Name | ||
| { | ||
| get | ||
| { | ||
| return "ImageLoader"; | ||
| } | ||
| } | ||
|
|
||
| [ReactMethod] | ||
| public void prefetchImage(string uriString, IPromise promise) | ||
| { | ||
| promise.Reject(ErrorPrefetchFailure, "Prefetch is not yet implemented."); | ||
| } | ||
|
|
||
| [ReactMethod] | ||
| public void getSize(string uriString, IPromise promise) | ||
| { | ||
| if (string.IsNullOrEmpty(uriString)) | ||
| { | ||
| promise.Reject(ErrorInvalidUri, "Cannot get the size of an image for an empty URI."); | ||
| return; | ||
| } | ||
|
|
||
| DispatcherHelpers.RunOnDispatcher(async () => | ||
| { | ||
| try | ||
| { | ||
| var bitmapImage = new BitmapImage(); | ||
| bitmapImage.BeginInit(); | ||
| var loadQuery = bitmapImage.GetStreamLoadObservable() | ||
| .Where(status => status.LoadStatus == ImageLoadStatus.OnLoadEnd) | ||
| .FirstAsync() | ||
| .Replay(1); | ||
|
|
||
| using (loadQuery.Connect()) | ||
| { | ||
| using (var stream = BitmapImageHelpers.GetStreamAsync(uriString)) | ||
| { | ||
| bitmapImage.StreamSource = stream; | ||
| } | ||
|
|
||
| await loadQuery; | ||
| bitmapImage.EndInit(); | ||
|
|
||
| promise.Resolve(new JObject | ||
| { | ||
| { "width", bitmapImage.PixelWidth }, | ||
| { "height", bitmapImage.PixelHeight }, | ||
| }); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| promise.Reject(ErrorGetSizeFailure, ex.Message); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ReactWindows/ReactNative.Shared.Tests/Modules/WebSocket/WebSocketModuleTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¯\_(ツ)_/¯